title: Exceptions and error codes: mixing them the right way
body: <p>I am developing a C++ dongle communication library. The library would provide an unified interface to communicate with a range of remote code execution dongles like SenseLock, KEYLOK, Guardant Code.</p>
  
  <p>The dongles are based on a smart card technology and have an internal file system and RAM.</p>
  
  <p>A typical operation routine involves (1) enumeration of dongles connected to the USB ports, (2) connection to a dongle selected, (3) execution of the named module passing input and collecting output data.</p>
  
  <p>Well, it is trivial that all of these stages can end up with an error. There can be many cases, but the most general are:</p>
  
  <ul>
  <li>A dongle is not found (sure a fatal case).</li>
  <li>A dongle connection failure (a fatal case).</li>
  <li>The execution module specified is not found within the dongle (?).</li>
  <li>The operation requested failed due to timeout (?).</li>
  <li>The operation requested needs authorization (a recoverable case I suppose).</li>
  <li>A memory error occurred while executing a module in a dongle (sure a fatal case).</li>
  <li>A file system error occurred in a dongle (sure a fatal case).</li>
  </ul>
  
  <p><em>? - I don't know yet if the case is considered fatal or not.</em></p>
  
  <p>I am still deciding whether to throw exceptions, to return an error codes, or to implement a methods for both cases.</p>
  
  <p><strong>The questions are:</strong></p>
  
  <ol>
  <li>Do exceptions replace the error codes completely or maybe I need to use them only for "fatal cases"?</li>
  <li>Is mixing two paradigms (exceptions and error codes) considered a good idea?</li>
  <li>Is it good idea to provide user with two conceptions?</li>
  <li>Are there any good examples of the exceptions and error codes mixing conception?</li>
  <li>How would you implement this?</li>
  </ol>
  
  <h2>Update 1.</h2>
  
  <p>It would be interesting to see more opinions from different perspectives, so I decided to add a 100 reputation bounty to the question.</p>