Home | History | Annotate | Line # | Download | only in manual
      1 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
      2 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Chapter5. Diagnostics</title><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><meta name="keywords" content="ISO C++, library" /><meta name="keywords" content="ISO C++, runtime, library" /><link rel="home" href="../index.html" title="The GNU C++ Library" /><link rel="up" href="std_contents.html" title="PartII. Standard Contents" /><link rel="prev" href="termination.html" title="Termination" /><link rel="next" href="errno.html" title="Use of errno by the library" /></head><body><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">Chapter5.
      3   Diagnostics
      4   
      5 </th></tr><tr><td width="20%" align="left"><a accesskey="p" href="termination.html">Prev</a></td><th width="60%" align="center">PartII.
      6     Standard Contents
      7   </th><td width="20%" align="right"><a accesskey="n" href="errno.html">Next</a></td></tr></table><hr /></div><div class="chapter"><div class="titlepage"><div><div><h2 class="title"><a id="std.diagnostics"></a>Chapter5.
      8   Diagnostics
      9   <a id="id-1.3.4.3.1.1.1" class="indexterm"></a>
     10 </h2></div></div></div><div class="toc"><p><strong>Table of Contents</strong></p><dl class="toc"><dt><span class="section"><a href="diagnostics.html#std.diagnostics.exceptions">Exceptions</a></span></dt><dd><dl><dt><span class="section"><a href="diagnostics.html#std.diagnostics.exceptions.api">API Reference</a></span></dt><dt><span class="section"><a href="diagnostics.html#std.diagnostics.exceptions.data">Adding Data to <code class="classname">exception</code></a></span></dt></dl></dd><dt><span class="section"><a href="errno.html">Use of errno by the library</a></span></dt><dt><span class="section"><a href="concept_checking.html">Concept Checking</a></span></dt></dl></div><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="std.diagnostics.exceptions"></a>Exceptions</h2></div></div></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="std.diagnostics.exceptions.api"></a>API Reference</h3></div></div></div><p>
     11       Most exception classes are defined in one of the standard headers
     12       <code class="filename">&lt;exception&gt;</code>,
     13       <code class="filename">&lt;stdexcept&gt;</code>,
     14       <code class="filename">&lt;new&gt;</code>, and
     15       <code class="filename">&lt;typeinfo&gt;</code>.
     16       The C++ 2011 revision of the standard added more exception types
     17       in the headers
     18       <code class="filename">&lt;functional&gt;</code>,
     19       <code class="filename">&lt;future&gt;</code>,
     20       <code class="filename">&lt;regex&gt;</code>, and
     21       <code class="filename">&lt;system_error&gt;</code>.
     22       The C++ 2017 revision of the standard added more exception types
     23       in the headers
     24       <code class="filename">&lt;any&gt;</code>,
     25       <code class="filename">&lt;filesystem&gt;</code>,
     26       <code class="filename">&lt;optional&gt;</code>, and
     27       <code class="filename">&lt;variant&gt;</code>.
     28     </p><p>
     29       All exceptions thrown by the library have a base class of type
     30       <code class="classname">std::exception</code>,
     31       defined in <code class="filename">&lt;exception&gt;</code>.
     32       This type has no <code class="classname">std::string</code> member.
     33     </p><p>
     34       Derived from this are several classes that may have a
     35       <code class="classname">std::string</code> member. A full hierarchy can be
     36       found in the source documentation.
     37     </p></div><div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="std.diagnostics.exceptions.data"></a>Adding Data to <code class="classname">exception</code></h3></div></div></div><p>
     38       The standard exception classes carry with them a single string as
     39       data (usually describing what went wrong or where the 'throw' took
     40     place).  It's good to remember that you can add your own data to
     41     these exceptions when extending the hierarchy:
     42    </p><pre class="programlisting">
     43    struct My_Exception : public std::runtime_error
     44    {
     45      public:
     46        My_Exception (const string&amp; whatarg)
     47 	   : std::runtime_error(whatarg), e(errno), id(GetDataBaseID()) { }
     48        int  errno_at_time_of_throw() const { return e; }
     49        DBID id_of_thing_that_threw() const { return id; }
     50      protected:
     51        int    e;
     52        DBID   id;     // some user-defined type
     53    };
     54    </pre></div></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="termination.html">Prev</a></td><td width="20%" align="center"><a accesskey="u" href="std_contents.html">Up</a></td><td width="40%" align="right"><a accesskey="n" href="errno.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Termination</td><td width="20%" align="center"><a accesskey="h" href="../index.html">Home</a></td><td width="40%" align="right" valign="top">Use of errno by the library</td></tr></table></div></body></html>