<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>TR2 Diagnostics Enhancements</title>
</head>

<body>

<p>Doc. no.&nbsp;&nbsp; N2174=07-0034<br>
Date:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<!--webbot bot="Timestamp" s-type="EDITED" s-format="%Y-%m-%d" startspan -->2007-03-06<!--webbot bot="Timestamp" endspan i-checksum="12214" --><br>
Project:&nbsp;&nbsp;&nbsp;&nbsp; Programming Language C++<br>
Reply to:&nbsp;&nbsp; Beman Dawes &lt;<a href="mailto:bdawes@acm.org">bdawes@acm.org</a>&gt;</p>

<h1>Diagnostics Enhancements for C++0x</h1>

<p><a href="#Introduction">Introduction</a><br>
<a href="#Design_Rationale">Design Rationale</a><br>
<a href="#History">History</a><br>
<a href="#Acknowledgements">Acknowledgements</a><br>
<a href="#Proposed">Proposed changes to the Working Paper</a><br>
&nbsp;&nbsp;&nbsp; <a href="#system_error">Header &lt;system_error&gt;</a><br>
&nbsp;&nbsp;&nbsp; <a href="#system_error">Class system_error</a><br>
&nbsp;&nbsp;&nbsp; <a href="#error_category">Class error_category</a><br>
&nbsp;&nbsp;&nbsp; <a href="#error_code">Class error_code</a></p>
<h2><a name="Introduction">Introduction</a></h2>
<p>Error conditions originating from the operating system or other low-level 
application program interfaces (API's) are typically reported via an integer 
representing an error code. On the other hand, the preferred mechanism for C++ libraries, 
including the standard library, is to report such errors by throwing an 
exception. Experience with the progenitors of the Filesystem Library (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1975.html">N1975</a>), 
the Networking Library (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2054.pdf">N2054</a>), 
and with similar <a href="http://www.boost.org">Boost</a> libraries has shown 
that such exceptions need to include the original error code to allow programs 
to undertake error-condition specific recovery actions.</p>
<p>That experience also found that while exceptions are the preferred default 
error code reporting mechanism, programs that use libraries dependent on 
low-level  API's&nbsp;need overloads reporting error conditions via error 
code arguments and/or return values rather than via throwing exceptions. 
Otherwise, when errors are not exceptional occurrences 
and must be dealt with as they arise, programs become littered with try/catch 
blocks, unreadable, and very inefficient.</p>
<p>The proposed diagnostic enhancements were originally slated for TR2 (<a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n2066.html">N2066</a>). They are 
now proposed for C++0x so that they can be used by C++0x threads libraries.</p>
<h2><a name="Design_Rationale">Design Rationale</a></h2>
<p>These diagnostic components are packaged in a single header to follow the 
standard library's practice of  large granularity headers. The components are not simply 
added to <code>&lt;stdexcept&gt;</code> to hold down dependencies in <code>&lt;stdexcept&gt;</code>.</p>
<p>The header is named <code>&lt;system_error&gt;</code> to emphasize the role its 
contents play, and to emphasize the <code>system_error</code> exception class. 
This is also intended to present class <code>error_code</code> as an adjunct to 
error reporting by exception, rather than a completely separate error handling 
mechanism.</p>
<p><code>error_code</code>&nbsp; is designed as a value type so it can be copied 
without slicing and does not requiring heap allocation, but to 
have polymorphic behavior based on the error category. This is achieved by 
abstract base class <code>error_category</code> supplying the polymorphic 
behavior, and <code>error_code</code> containing a pointer to an object of a 
type derived from <code>error_category</code>.</p>
<p>The <code>operator&lt;&lt;</code> overload for <code>error_code</code> eliminates a 
misleading conversion to bool in code like <code>cout &lt;&lt; ec</code>, where <code>
ec</code> is of type <code>error_code</code>. It is also useful in its own 
right.</p>
<h2><a name="History">History</a></h2>
<p><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2006/n1975.html">
N1975</a>, Filesystem Library Proposal for TR2, accepted for Library Technical 
Report 2 (TR2) at the Berlin meeting, included additional components to 
supplement the Standard Library's Diagnostics clause. Since then, these error 
reporting components have received wider public scrutiny and enhancements have 
been made to the design. The enhanced version has been used by N2054, Networking 
Library Proposal for TR2, demonstrating that these error reporting components 
are useful beyond the original Filesystem Library.</p>
<p>The original proposal viewed error categories as a binary choice between
<code>errno</code> (i.e. POSIX-style) and the native operating system's error 
codes. The proposed components now allow as many additional error categories 
as are needed by either implementations or by users. The need to support 
additional error categories, for example, occurs in some networking library 
implementations because they are built on top of the POSIX <code>getaddrinfo</code> API that uses error codes 
not based on <code>errno</code>.</p>
  <h2><a name="Acknowledgements">Acknowledgements</a></h2>
  <p>Christopher Kohlhoff and Peter Dimov made important contributions to the 
  design. Comments and suggestions were also received from Pavel Vozenilek, 
  Gennaro Prota, Dave Abrahams, Jeff Garland, Iain Hanson, Oliver Kowalke, and 
  Oleg Abrosimov. Christopher Kohlhoff suggested several improvements to the 
  N2066 paper. Johan Nilsson's comments led to several of the refinements in 
  N2066 </p>

<h2><a name="Proposed">Proposed</a> changes to the Working Paper</h2>

<p><i>Add to Chapter 19, Diagnostics library [diagnostics], paragraph 2, an 
additional line in the Diagnostics library summary table, so it reads:</i></p>
<p align="left"><span style="font-weight: 400">Table 26: Diagnostics library 
summary</span></p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="60%">
  <tr>
    <td width="50%" align="center"><b>Subclause</b></td>
    <td width="50%" align="center"><b>Header(s)</b></td>
  </tr>
  <tr>
    <td width="50%"><span style="font-weight: 400">19.1 Exception classes</span></td>
    <td width="50%"><span style="font-weight: 400"><code>&lt;stdexcept&gt;</code></span></td>
  </tr>
  <tr>
    <td width="50%"><span style="font-weight: 400">19.2 Assertions</span></td>
    <td width="50%"><span style="font-weight: 400"><code>&lt;cassert&gt;</code></span></td>
  </tr>
  <tr>
    <td width="50%"><span style="font-weight: 400">19.3 Error numbers</span></td>
    <td width="50%"><span style="font-weight: 400"><code>&lt;cerrno&gt;</code></span></td>
  </tr>
  <tr>
    <td width="50%"><u><font color="#228822">19.4 System error support</font></u></td>
    <td width="50%"><u><font color="#228822"><code>&lt;system_error&gt;</code></font></u></td>
  </tr>
</table>
<p><i>Change 19.3, Error numbers [errno], as indicated:</i></p>
<p>Header &lt;cerrno&gt; (Table 28):</p>
<p>Table 28: Header &lt;cerrno&gt; synopsis</p>
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%">
  <tr>
    <td width="100%"><b>Type:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
    Name(s)</b></td>
  </tr>
  <tr>
    <td width="100%"><b>Macros:</b> <u><font color="#228822">E2BIG EACCES 
    EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN EALREADY EBADF EBADMSG EBUSY 
    ECANCELED ECHILD ECONNABORTED ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ</font></u> 
    EDOM <u><font color="#228822">EEXIST EFAULT EFBIG EHOSTUNREACH EIDRM</font></u> 
    EILSEQ <u><font color="#228822">EINPROGRESS EINTR EINVAL EIO EISCONN EISDIR 
    ELOOP EMFILE EMLINK EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH 
    ENFILE ENOBUFS ENODATA ENODEV ENOENT ENOEXEC ENOLCK ENOLINK ENOMEM ENOMSG 
    ENOPROTOOPT ENOSPC ENOSR ENOSTR ENOSYS ENOTCONN ENOTDIR ENOTEMPTY ENOTSOCK 
    ENOTSUP ENOTTY ENXIO EOPNOTSUPP EOTHER EOVERFLOW EPERM EPIPE EPROTO 
    EPROTONOSUPPORT EPROTOTYPE</font></u> ERANGE <u><font color="#228822">EROFS 
    ESPIPE ESRCH ETIME ETIMEDOUT ETXTBSY EWOULDBLOCK EXDEV</font></u> errno</td>
  </tr>
</table>
<p>The contents are the same as the <strike><font color="#FF0000">Standard C 
library</font></strike> <font color="#228822"><u>POSIX</u></font> header <code>&lt;errno.h&gt;</code>, 
except that <code>errno</code> shall be defined as a macro<u><font color="#228822">, 
and an additional macro <code>EOTHER</code> shall be defined to represent errors 
not specified by the POSIX standard</font></u>.</p>
<p><i>Add to Chapter 19, Diagnostics library [diagnostics], the following new 
subclause. The Project Editor may wish to identify it as </i>19.4 System error support [sys_err_support.code]<i>.</i></p>
<p>This subclause describes components that the standard library and C++ 
programs may use to report error conditions originating from the operating 
system or other low-level application program interfaces.</p>
<p>Component described in this subclause shall not change the value of <code>
errno</code> ([errno]). Implementations are encouraged but not required to leave 
unchanged the error states provided by other libraries.</p>
<h3><a name="Header">Header</a> &lt;system_error&gt;</h3>
<pre>namespace std
{
  class <a href="#system_error">system_error</a>;
  class <a href="#error_code">error_code</a>;
  class <a href="#error_category">error_category</a>;

  extern const error_category&amp; errno_category;
  extern const error_category&amp; native_category;

  template &lt;class charT, class traits&gt;
    std::basic_ostream&lt;charT,traits&gt;&amp;
      operator&lt;&lt;(basic_ostream&lt;charT,traits&gt;&amp; os, const error_code &amp; ec);

  size_t hash_value(const error_code &amp; ec);</pre>
<pre>  namespace error
  {
    extern const error_code address_family_not_supported;
    extern const error_code address_in_use;
    extern const error_code address_not_available;
    extern const error_code already_connected;
    extern const error_code argument_list_too_long;
    extern const error_code argument_out_of_domain;
    extern const error_code bad_address;
    extern const error_code bad_file_descriptor;
    extern const error_code bad_message;
    extern const error_code broken_pipe;
    extern const error_code connection_aborted;
    extern const error_code connection_already_in_progress;
    extern const error_code connection_refused;
    extern const error_code connection_reset;
    extern const error_code cross_device_link;
    extern const error_code destination_address_required;
    extern const error_code device_or_resource_busy;
    extern const error_code directory_not_empty;
    extern const error_code executable_format_error;
    extern const error_code file_exists;
    extern const error_code file_too_large;
    extern const error_code filename_too_long;
    extern const error_code function_not_supported;
    extern const error_code host_unreachable;
    extern const error_code identifier_removed;
    extern const error_code illegal_byte_sequence;
    extern const error_code inappropriate_io_control_operation;
    extern const error_code interrupted;
    extern const error_code invalid_argument;
    extern const error_code invalid_seek;
    extern const error_code io_error;
    extern const error_code is_a_directory;
    extern const error_code message_size;
    extern const error_code network_down;
    extern const error_code network_reset;
    extern const error_code network_unreachable;
    extern const error_code no_buffer_space;
    extern const error_code no_child_process;
    extern const error_code no_link;
    extern const error_code no_lock_available;
    extern const error_code no_message_available;
    extern const error_code no_message;
    extern const error_code no_protocol_option;
    extern const error_code no_space_on_device;
    extern const error_code no_stream_resources;
    extern const error_code no_such_device_or_address;
    extern const error_code no_such_device;
    extern const error_code no_such_file_or_directory;
    extern const error_code no_such_process;
    extern const error_code not_a_directory;
    extern const error_code not_a_socket;
    extern const error_code not_a_stream;
    extern const error_code not_connected;
    extern const error_code not_enough_memory;
    extern const error_code not_supported;
    extern const error_code operation_canceled;
    extern const error_code operation_in_progress;
    extern const error_code operation_not_permitted;
    extern const error_code operation_not_supported;
    extern const error_code operation_would_block;
    extern const error_code other;
    extern const error_code permission_denied;
    extern const error_code protocol_error;
    extern const error_code protocol_not_supported;
    extern const error_code read_only_file_system;
    extern const error_code resource_deadlock_would_occur;
    extern const error_code resource_unavailable_try_again;
    extern const error_code result_out_of_range;
    extern const error_code stream_timeout;
    extern const error_code text_file_busy;
    extern const error_code timed_out;
    extern const error_code too_many_files_open_in_system;
    extern const error_code too_many_files_open;
    extern const error_code too_many_links;
    extern const error_code too_many_synbolic_link_levels;
    extern const error_code value_too_large;
    extern const error_code wrong_protocol_type;
  }
}</pre>
<h3>Error category objects</h3>
<p>Predefined objects <code>errno_category</code> 
and <code>native_category</code> identify portable and native error 
codes, respectively.</p>
<h3>Non-member functions</h3>
<pre>template &lt;class charT, class traits&gt;
  std::basic_ostream&lt;charT,traits&gt;&amp;
    operator&lt;&lt;(basic_ostream&lt;charT,traits&gt;&amp; os, const error_code &amp; ec);</pre>
<blockquote>
<p><i>Effects:</i> <code>os &lt;&lt; ec.category().name() &lt;&lt; ':' &lt;&lt; ec.value()</code>.</p>
<p><i>Returns:</i> <code>os</code>.</p>
</blockquote>
<pre>size_t <a name="hash_value">hash_value</a>( const error_code&amp; ec );</pre>
<blockquote>
  <p><i>Returns: </i>&nbsp;A hash value representing <code>ec</code>.</p>
</blockquote>

<h3><code>errno_category</code> constants</h3>
<p>The meaning of each <code>error_code</code> constant value declared in 
namespace <code>error</code> shall correspond to the equivalent macro from 
header <code>&lt;cerrno&gt;</code>, as defined in the table below.</p>

<blockquote>  
<table border="1" cellpadding="5" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111">
  <tr>
    <td align="center"><i><b>Name</b></i></td>
    <td align="center"><b><i>&lt;cerrno&gt;</i></b><i><b> macro</b></i></td>
  </tr>
  <tr>
    <td><code>address_family_not_supported</code></td>
    <td>
      <code>EAFNOSUPPORT </code>
    </td>
  </tr>
  <tr>
    <td><code>address_in_use</code></td>
    <td>
      <code>EADDRINUSE </code>
    </td>
  </tr>
  <tr>
    <td><code>address_not_available</code></td>
    <td>
      <code>EADDRNOTAVAIL </code>
    </td>
  </tr>
  <tr>
    <td><code>already_connected</code></td>
    <td>
      <code>EISCONN </code>
    </td>
  </tr>
  <tr>
    <td><code>argument_list_too_long</code></td>
    <td>
      <code>E2BIG </code>
    </td>
  </tr>
  <tr>
    <td><code>argument_out_of_domain</code></td>
    <td>
      <code>EDOM </code>
    </td>
  </tr>
  <tr>
    <td><code>bad_address</code></td>
    <td>
      <code>EFAULT </code>
    </td>
  </tr>
  <tr>
    <td><code>bad_file_descriptor</code></td>
    <td>
      <code>EBADF </code>
    </td>
  </tr>
  <tr>
    <td><code>bad_message</code></td>
    <td>
      <code>EBADMSG </code>
    </td>
  </tr>
  <tr>
    <td><code>broken_pipe</code></td>
    <td>
      <code>EPIPE </code>
    </td>
  </tr>
  <tr>
    <td><code>connection_aborted</code></td>
    <td>
      <code>ECONNABORTED </code>
    </td>
  </tr>
  <tr>
    <td><code>connection_already_in_progress</code></td>
    <td>
      <code>EALREADY </code>
    </td>
  </tr>
  <tr>
    <td><code>connection_refused</code></td>
    <td>
      <code>ECONNREFUSED </code>
    </td>
  </tr>
  <tr>
    <td><code>connection_reset</code></td>
    <td>
      <code>ECONNRESET </code>
    </td>
  </tr>
  <tr>
    <td><code>cross_device_link</code></td>
    <td>
      <code>EXDEV </code>
    </td>
  </tr>
<tr>
  <td><code>destination_address_required</code></td>
  <td>
    <code>EDESTADDRREQ </code>
  </td>
</tr>
<tr>
  <td><code>device_or_resource_busy</code></td>
  <td>
    <code>EBUSY </code>
  </td>
</tr>
<tr>
  <td><code>directory_not_empty</code></td>
  <td>
    <code>ENOTEMPTY </code>
  </td>
</tr>
<tr>
  <td><code>executable_format_error</code></td>
  <td>
    <code>ENOEXEC </code>
  </td>
</tr>
<tr>
  <td><code>file_exists</code></td>
  <td>
    <code>EEXIST </code>
  </td>
</tr>
<tr>
  <td><code>file_too_large</code></td>
  <td>
    <code>EFBIG </code>
  </td>
</tr>
<tr>
  <td><code>filename_too_long</code></td>
  <td>
    <code>ENAMETOOLONG </code>
  </td>
</tr>
<tr>
  <td><code>function_not_supported</code></td>
  <td>
    <code>ENOSYS </code>
  </td>
</tr>
<tr>
  <td><code>host_unreachable</code></td>
  <td>
    <code>EHOSTUNREACH </code>
  </td>
</tr>
<tr>
  <td><code>identifier_removed</code></td>
  <td>
    <code>EIDRM </code>
  </td>
</tr>
<tr>
  <td><code>illegal_byte_sequence</code></td>
  <td>
    <code>EILSEQ </code>
  </td>
</tr>
<tr>
  <td><code>inappropriate_io_control_operation</code></td>
  <td>
    <code>ENOTTY </code>
  </td>
</tr>
<tr>
  <td><code>interrupted</code></td>
  <td>
    <code>EINTR </code>
  </td>
</tr>
<tr>
  <td><code>invalid_argument</code></td>
  <td>
    <code>EINVAL </code>
  </td>
</tr>
<tr>
  <td><code>invalid_seek</code></td>
  <td>
    <code>ESPIPE </code>
  </td>
</tr>
<tr>
  <td><code>io_error</code></td>
  <td>
    <code>EIO </code>
  </td>
</tr>
<tr>
  <td><code>is_a_directory</code></td>
  <td>
    <code>EISDIR </code>
  </td>
</tr>
<tr>
  <td><code>message_size</code></td>
  <td>
    <code>EMSGSIZE </code>
  </td>
</tr>
<tr>
  <td><code>network_down</code></td>
  <td>
    <code>ENETDOWN </code>
  </td>
</tr>
<tr>
  <td><code>network_reset</code></td>
  <td>
    <code>ENETRESET </code>
  </td>
</tr>
<tr>
  <td><code>network_unreachable</code></td>
  <td>
    <code>ENETUNREACH </code>
  </td>
</tr>
<tr>
  <td><code>no_buffer_space</code></td>
  <td>
    <code>ENOBUFS </code>
  </td>
</tr>
<tr>
  <td><code>no_child_process</code></td>
  <td>
    <code>ECHILD </code>
  </td>
</tr>
<tr>
  <td><code>no_link</code></td>
  <td>
    <code>ENOLINK </code>
  </td>
</tr>
<tr>
  <td><code>no_lock_available</code></td>
  <td>
    <code>ENOLCK </code>
  </td>
</tr>
<tr>
  <td><code>no_message_available</code></td>
  <td>
    <code>ENODATA </code>
  </td>
</tr>
<tr>
  <td><code>no_message</code></td>
  <td>
    <code>ENOMSG </code>
  </td>
</tr>
<tr>
  <td><code>no_protocol_option</code></td>
  <td>
    <code>ENOPROTOOPT </code>
  </td>
</tr>
<tr>
  <td><code>no_space_on_device</code></td>
  <td>
    <code>ENOSPC </code>
  </td>
</tr>
<tr>
  <td><code>no_stream_resources</code></td>
  <td>
    <code>ENOSR </code>
  </td>
</tr>
<tr>
  <td><code>no_such_device_or_address</code></td>
  <td>
    <code>ENXIO </code>
  </td>
</tr>
<tr>
  <td><code>no_such_device</code></td>
  <td>
    <code>ENODEV </code>
  </td>
</tr>
<tr>
  <td><code>no_such_file_or_directory</code></td>
  <td>
    <code>ENOENT </code>
  </td>
</tr>
<tr>
  <td><code>no_such_process</code></td>
  <td>
    <code>ESRCH </code>
  </td>
</tr>
<tr>
  <td><code>not_a_directory</code></td>
  <td>
    <code>ENOTDIR </code>
  </td>
</tr>
  <tr>
  <td><code>not_a_socket</code></td>
  <td>
    <code>ENOTSOCK </code>
  </td>
  </tr>
<tr>
  <td><code>not_a_stream</code></td>
  <td>
    <code>ENOSTR </code>
  </td>
</tr>
<tr>
  <td><code>not_connected</code></td>
  <td>
    <code>ENOTCONN </code>
  </td>
</tr>
<tr>
  <td><code>not_enough_memory</code></td>
  <td>
    <code>ENOMEM </code>
  </td>
</tr>
<tr>
  <td><code>not_supported</code></td>
  <td>
    <code>ENOTSUP </code>
  </td>
</tr>
<tr>
  <td><code>operation_canceled</code></td>
  <td>
    <code>ECANCELED </code>
  </td>
</tr>
<tr>
  <td><code>operation_in_progress</code></td>
  <td>
    <code>EINPROGRESS </code>
  </td>
</tr>
<tr>
  <td><code>operation_not_permitted</code></td>
  <td>
    <code>EPERM </code>
  </td>
</tr>
<tr>
  <td><code>operation_not_supported</code></td>
  <td>
    <code>EOPNOTSUPP </code>
  </td>
</tr>
<tr>
  <td><code>operation_would_block</code></td>
  <td>
    <code>EWOULDBLOCK </code>
  </td>
</tr>
<tr>
  <td><code>other</code></td>
  <td>
    <code>EOTHER</code></td>
</tr>
<tr>
  <td><code>permission_denied</code></td>
  <td>
    <code>EACCES </code>
  </td>
</tr>
<tr>
  <td><code>protocol_error</code></td>
  <td>
    <code>EPROTO </code>
  </td>
</tr>
<tr>
  <td><code>protocol_not_supported</code></td>
  <td>
    <code>EPROTONOSUPPORT </code>
  </td>
</tr>
<tr>
  <td><code>read_only_file_system</code></td>
  <td>
    <code>EROFS </code>
  </td>
</tr>
<tr>
  <td><code>resource_deadlock_would_occur</code></td>
  <td>
    <code>EDEADLK </code>
  </td>
</tr>
<tr>
  <td><code>resource_unavailable_try_again</code></td>
  <td>
    <code>EAGAIN </code>
  </td>
</tr>
<tr>
  <td><code>result_out_of_range</code></td>
  <td>
    <code>ERANGE </code>
  </td>
</tr>
<tr>
  <td><code>stream_timeout</code></td>
  <td>
    <code>ETIME </code>
  </td>
</tr>
<tr>
  <td><code>text_file_busy</code></td>
  <td>
    <code>ETXTBSY </code>
  </td>
</tr>
<tr>
  <td><code>timed_out</code></td>
  <td>
    <code>ETIMEDOUT </code>
  </td>
</tr>
<tr>
  <td><code>too_many_files_open_in_system</code></td>
  <td>
    <code>ENFILE </code>
  </td>
</tr>
<tr>
  <td><code>too_many_files_open</code></td>
  <td>
    <code>EMFILE </code>
  </td>
</tr>
<tr>
  <td><code>too_many_links</code></td>
  <td>
    <code>EMLINK </code>
  </td>
</tr>
<tr>
  <td><code>too_many_synbolic_link_levels</code></td>
  <td>
    <code>ELOOP </code>
  </td>
</tr>
<tr>
  <td><code>value_too_large</code></td>
  <td>
    <code>EOVERFLOW </code>
  </td>
</tr>
<tr>
  <td><code>wrong_protocol_type</code></td>
  <td>
    <code>EPROTOTYPE </code>
  </td>
</tr>
</table>
</blockquote>

<p><i>[Note:</i> The <code>other</code> error code is used to indicate errors 
that have no POSIX equivalent. <i>--end note]</i></p>

<h3>Class <code>
<a name="system_error">system_error</a></code></h3>
<p>The class <code>system_error</code> defines the type of objects thrown as 
exceptions to report error conditions that have an associated error code. Such 
error conditions typically originate from the operating system or other 
low-level application program interfaces.</p>
<pre>namespace std
{
  class system_error : public std::runtime_error
  {
  public:
    system_error(error_code ec, const std::string&amp; what_arg);
    system_error(error_code::value_type ev, error_category ecat,
                 const std::string&amp; what_arg);

    const error_code&amp; code() const throw();
    const char*       what() const throw();

  private:
    string msg; // <b><i>for exposition only</i></b>
  };
}</pre>
<pre>system_error(error_code ec, const std::string&amp; what_arg);</pre>
<blockquote>
  <p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
  <p><i>Postcondition:</i> <code>code() == ec <br>
&nbsp; &amp;&amp; strcmp( this-&gt;runtime_error::what(), what_arg.c_str()) == 0</code></p>
</blockquote>
<pre>system_error(error_code::value_type ev, error_category ecat,
             const std::string&amp; what_arg);</pre>
<blockquote>
  <p><i>Effects:</i> Constructs an object of class <code>system_error</code>.</p>
  <p><i>Postcondition:</i> <code>code() == error_code(ev, ecat)<br>
&nbsp; &amp;&amp; strcmp( this-&gt;runtime_error::what(), what_arg.c_str()) == 0</code></p>
</blockquote>
<pre>const error_code&amp; code() const;</pre>
<blockquote>
  <p><i>Returns:</i> <code>ec</code> or <code>error_code(ev, ecat)</code>, from 
  the constructor, as appropriate.</p>
</blockquote>
<pre>const char* what() const;</pre>
<blockquote>
  <p><i>Returns: </i>A string incorporating <code>
  this-&gt;runtime_error::what()</code> and <code>
  code.message()</code>.</p>
  <p>[<i>Note:</i> One possible implementation would be:</p>
  <blockquote>
    <pre>if (msg.empty())
{
  try
  {
    msg = this-&gt;runtime_error::what();
    if ( code() )
    {
      if ( !msg.empty() ) msg += &quot;: &quot;;
      msg += code().message();
    }
  }
  catch (...) { return runtime_error::what(); }
}
return msg.c_str();</pre>
  </blockquote>
    <p><i>--end note</i>]</p>
</blockquote>
<h3>Class <code><a name="error_category">error_category</a></code></h3>
<p>The class <code>error_category</code> defines the base class for types used 
to identify the source and encoding of a particular category of error code.</p>
<p><i>[Note:</i> Classes may be derived from <code>error_category</code> 
to support additional categories of errors. <i>--end note]</i></p>
<pre>namespace std
{
  class error_category
  {
  public:
    virtual const std::string &amp; name() const=0;
    virtual int to_errno(error_code::value_type ev) const=0;
    virtual string message(error_code::value_type ev) const=0;
    virtual wstring wmessage(error_code::value_type ev) const=0;

    bool operator==(const error_category&amp; rhs) const;
    bool operator!=(const error_category&amp; rhs) const;
  };
}</pre>
<h3>Class <code>error_category</code> virtual members</h3>
<p>Classes derived from <code>error_category</code> shall behave as specified in 
this subclause.</p>
<pre>virtual const std::string &amp; name() const=0;</pre>
<blockquote>
  <p><i>Returns: </i>a string naming the error category.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>virtual int to_errno(error_code::value_type ev) const=0;</pre>
<blockquote>
  <p><i>Returns:</i> A POSIX error 
number that corresponds to <code>ev</code> if such a corresponding POSIX error 
  number exists, otherwise <code>EOTHER</code>.</p>
<p><i>[Note:</i>&nbsp; Since the value of <code>ev</code> is not bounded, the 
intent is that implementations translate 
common values to the equivalent POSIX error number and translate the rest to
<code>EOTHER</code><i>.</i> <i>--end note]</i></p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>virtual string message(error_code::value_type ev) const=0;</pre>
<blockquote>
  <p><i>Returns:</i> A string that describes the error condition denoted by
  <code>ev</code>.</p>
<p><i>[Note:</i> The intent is to return a locale sensitive string that describes the error 
corresponding to <code>ev</code>.&nbsp; <i>--end note.]</i></p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>virtual wstring wmessage(error_code::value_type ev) const=0;</pre>
<blockquote>
  <p><i>Returns:</i> A string that describes the error condition denoted by
  <code>ev</code>.</p>
<p><i>[Note:</i> The intent is to return a locale sensitive string that describes the error 
corresponding to <code>ev</code>.&nbsp; <i>--end note.]</i></p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<h3>Class <code>error_category</code> non-virtual members</h3>
<p><code>bool operator==(const error_category&amp; rhs) const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>this == &amp;rhs</code>.</p>
</blockquote>
<p><code>bool operator!=(const error_category&amp; rhs) const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>this != &amp;rhs</code>.</p>
</blockquote>
<h3>Class <code>
<a name="error_code">error_code</a></code></h3>
<p>The class <code>error_code</code> defines the type of objects used to hold error code values, such as those originating from 
the operating system or other low-level application program interfaces.</p>
<p><i>[Note:</i> Class <code>error_code</code> as an adjunct to 
error reporting by exception, rather than a completely separate error handling 
mechanism. <i>--end note.]</i></p>
<pre>namespace std
{
  class error_code
  {
  public:
    typedef int_least32_t value_type;

    // constructors:
    error_code();
    error_code(value_type val, const error_category&amp; cat);

    // modifiers:
    void assign(value_type val, const error_category&amp; cat);
    void clear();

    // observers:
    value_type             value() const;
    const error_category&amp;  category() const;
    int                    to_errno() const;
    string                 message() const;
    wstring                wmessage() const;
    operator <i>unspecified-bool-type</i>() const;

    // relationals:
    bool operator==(const error_code&amp; rhs) const;
    bool operator!=(const error_code&amp; rhs) const;

  private:
    value_type            _val; // <b><i>for exposition only</i></b>
    const error_category* _cat; // <b><i>for exposition only</i></b>
  };
}</pre>
<h3>Class <code>
error_code</code> members</h3>
<pre>error_code();</pre>
<blockquote>
  <p><i>Effects: </i>Constructs an object of type <code>error_code</code>.</p>
  <p><i>Postconditions:</i> <code>_val == 0 &amp;&amp; _cat == &amp;errno_category</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>error_code(value_type val, const error_category&amp; cat);</pre>
<blockquote>
  <p><i>Effects: </i>Constructs an object of type <code>error_code</code>.</p>
  <p><i>Postconditions:</i> <code>_val == val &amp;&amp; _cat == &amp;cat</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<pre>void assign(value_type val, const error_category&amp; cat);</pre>
<blockquote>
  <p><i>Postconditions:</i> <code>_val == val &amp;&amp; _cat == &amp;cat</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
  <p><code>value_type value() const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>_val</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
  <p><code>error_category category() const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>_cat</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
  <p><code>int to_errno() const;</code></p>
<blockquote>
<p><i>Returns:</i>&nbsp; <code>category().to_errno(value())</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
  <p><code>string message() const;</code></p>
<blockquote>
<p><i>Returns:</i>&nbsp; <code>category().message(value())</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
  <p><code>wstring wmessage() const;</code></p>
<blockquote>
<p><i>Returns:</i>&nbsp; <code>category().wmessage(value())</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>operator <i>unspecified-bool-type</i>() const;</code></p>
<blockquote>
<p><i>Returns:</i> if <code>value() != value_type()</code>, returns a value that will evaluate
<code>true</code> in a boolean context; otherwise, returns a value that will 
evaluate <code>false</code> in a boolean context. The value type returned shall 
not be convertible to <code>int</code>.</p>
<p><i>Throws:</i> nothing.</p>
<p>[<i>Note: </i>This conversion can be used in contexts where a <code>bool</code> 
is expected (e.g., an <code>if</code> condition); however, implicit conversions 
(e.g., to <code>int</code>) that can occur with <code>bool</code> are not 
allowed, eliminating some sources of user error. One possible implementation 
choice for this type is pointer-to-member. <i>—end note </i>]</p>
</blockquote>
<p><code>bool operator==(const error_code rhs) const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>value() == rhs.value() &amp;&amp; category() == rhs.category()</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<p><code>bool operator!=(const error_code rhs) const;</code></p>
<blockquote>
<p><i>Returns:</i> <code>!(*this == rhs)</code>.</p>
  <p><i>Throws:</i> Nothing.</p>
</blockquote>
<hr>

</body>

</html>
