title: Use cases for std::error_code
body: <p>Lately I've been converting some libraries to use the <code>&lt;system_error&gt;</code> facilities in C++11.</p>
  
  <p>I'm having difficulty understanding the use cases for <code>std::error_code</code> vs. <code>std::error_condition</code>.  </p>
  
  <p>Note, <strong>I understand the difference</strong> - there are <a href="https://stackoverflow.com/questions/16687403/error-code-vs-error-condition">many questions on stackoverflow</a> which go over the difference. </p>
  
  <p>The basic difference is that <code>std::error_code</code> is supposed to represent a system- or platform-specific error, whereas <code>std::error_condition</code> is an abstract error that an API or user interface should return.</p>
  
  <p>Okay - but I'm having trouble understanding why we would ever use <code>std::error_code</code> in practice.  It seems to me you're either going to :</p>
  
  <ol>
  <li><p>Be dealing with a system specific error reporting mechanism (like
  say, <code>errno</code> or something returned from a POSIX call, or say, a call
  to <code>getsockopt</code> with <code>SO_ERROR</code> on Linux) which you can easily
  convert to an <code>std::error_condition</code> via the <code>std::errc</code> enums, which are supposed to be portable.</p></li>
  <li><p>Be using a user-defined category of errors, which represent application-level
  or business-logic errors, like "invalid social security number" or
  whatever - which also would be a use case for
  <code>std::error_condition</code>.</p></li>
  <li><p>Be dealing with some low-level interface or library which defines its own error reporting mechanism, such as OpenSSL, in which case you would be directly using platform-specific error mechanisms.  In this case you'd then need to convert or map these errors to an <code>std::error_code</code>.  But if you're going to go through the trouble of converting these platform specific errors to something generic like <code>std::error_code</code>, why not just convert to <code>std::error_condition</code>?</p></li>
  </ol>
  
  <p>Also, since POSIX system errors are supposed to be portable, and since they map one-to-one with <code>std::error_condition</code> via the <code>std::errc</code> enum, I can't find any use case for <code>std::error_code</code>.  Most Linux/UNIX system calls set <code>errno</code>, which is supposed to portably map to <code>std::error_condition</code>.</p>
  
  <p>So, I don't see any use case for <code>std::error_code</code> anywhere.  So, what are some example use cases where we would want to use <code>std::error_code</code> instead of <code>std::error_condition</code>?</p>