Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I tend to try to translate my errors at each layer so they make sense in that context. For example lets say you have a main program which calls a communications stack, which in turn calls an serial driver. The serial driver might have some errors like:</p> <pre><code>typedef enum { SER_NO_ERR, SER_TX_ERR, SER_BAD_ARGS, ... } SER_ERR; </code></pre> <p>The communications stack might have:</p> <pre><code>typedef enum { COMM_OK, COMM_TIMEOUT, COMM_TX_ERR, ... } COMM_ERR; </code></pre> <p>In your comm stack you might some code that looks like:</p> <pre><code>// lets assume you are using the global variables serErr and commErr // to store error codes for their respective libraries. serial_transmit(someDataPtr, someSize); switch(serErr) { case SER_NO_ERR: commErr = COMM_OK; break; case SER_BAD_ARGS: case SER_TX_ERR: commErr = COMM_TX_ERR; break; ... } </code></pre> <p>I realize that might introduce a fair amount of code but I like that it maintains the abstraction between the layers. You can also define some functions to handle the translations, like:</p> <pre><code>void comm_handle_serial_error(SER_ERR err) { //copy in the switch statement from above } </code></pre> <p>but the errors may mean different things in different contexts, so I recommend keeping that in mind as you design the system. </p> <p>Now at your highest level, all you have to do is worry about handling all of the errors defined by <code>COMM_ERR</code> when you call a communications function. Note that all of these examples are a bit contrived, but hopefully you get the idea.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload