OSDN Git Service

3497f3c96f753a2dc4763a941c60efe349813084
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / doc / xml / manual / diagnostics.xml
1 <?xml version='1.0'?>
2 <!DOCTYPE part PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" 
3  "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" 
4 [ ]>
5
6 <part id="manual.diagnostics" xreflabel="Diagnostics">
7 <?dbhtml filename="diagnostics.html"?>
8  
9 <partinfo>
10   <keywordset>
11     <keyword>
12       ISO C++
13     </keyword>
14     <keyword>
15       library
16     </keyword>
17   </keywordset>
18 </partinfo>
19
20 <title>
21   Diagnostics
22   <indexterm><primary>Diagnostics</primary></indexterm>
23 </title>
24
25 <chapter id="manual.diagnostics.exceptions" xreflabel="Exceptions">
26   <title>Exceptions</title>
27
28   <sect1 id="manual.diagnostics.exceptions.hierarchy" xreflabel="Exception Classes">
29     <title>Exception Classes</title>
30     <para>
31       All exception objects are defined in one of the standard header
32       files: <filename>exception</filename>,
33       <filename>stdexcept</filename>, <filename>new</filename>, and
34       <filename>typeinfo</filename>.
35     </para>
36
37     <para>
38       The base exception object is <classname>exception</classname>,
39       located in <filename>exception</filename>. This object has no
40       <classname>string</classname> member.
41     </para>
42
43     <para>
44       Derived from this are several classes that may have a
45       <classname>string</classname> member: a full hierarchy can be
46       found in the <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00233.html">source documentation</ulink>.
47     </para>
48
49   </sect1>
50   <sect1 id="manual.diagnostics.exceptions.data" xreflabel="Adding Data to Exceptions">
51     <title>Adding Data to Exceptions</title>
52     <para>
53       The standard exception classes carry with them a single string as
54       data (usually describing what went wrong or where the 'throw' took
55     place).  It's good to remember that you can add your own data to
56     these exceptions when extending the hierarchy:
57    </para>
58    <programlisting>
59    struct My_Exception : public std::runtime_error
60    {
61      public:
62        My_Exception (const string&amp; whatarg)
63            : std::runtime_error(whatarg), e(errno), id(GetDataBaseID()) { }
64        int  errno_at_time_of_throw() const { return e; }
65        DBID id_of_thing_that_threw() const { return id; }
66      protected:
67        int    e;
68        DBID   id;     // some user-defined type
69    };
70    </programlisting>
71
72   </sect1>  
73   <sect1 id="manual.diagnostics.exceptions.cancellation" xreflabel="Cancellation">
74     <title>Cancellation</title>
75     <para>
76     </para>
77   </sect1>  
78 </chapter>
79
80 <chapter id="manual.diagnostics.concept_checking" xreflabel="Concept Checking">
81   <title>Concept Checking</title>
82   <para>
83     In 1999, SGI added <quote>concept checkers</quote> to their
84     implementation of the STL: code which checked the template
85     parameters of instantiated pieces of the STL, in order to insure
86     that the parameters being used met the requirements of the
87     standard.  For example, the Standard requires that types passed as
88     template parameters to <classname>vector</classname> be
89     &quot;Assignable&quot; (which means what you think it means).  The
90     checking was done during compilation, and none of the code was
91     executed at runtime.
92    </para>
93    <para>
94      Unfortunately, the size of the compiler files grew significantly
95      as a result.  The checking code itself was cumbersome.  And bugs
96      were found in it on more than one occasion.
97    </para>
98    <para>
99      The primary author of the checking code, Jeremy Siek, had already
100      started work on a replacement implementation.  The new code has been
101      formally reviewed and accepted into
102    <ulink url="http://www.boost.org/libs/concept_check/concept_check.htm">the
103    Boost libraries</ulink>, and we are pleased to incorporate it into the
104    GNU C++ library.
105  </para>
106  <para>
107    The new version imposes a much smaller space overhead on the generated
108    object file.  The checks are also cleaner and easier to read and
109    understand.
110  </para>
111
112  <para>
113    They are off by default for all versions of GCC.
114    They can be enabled at configure time with
115    <ulink url="../configopts.html"><literal>--enable-concept-checks</literal></ulink>.
116    You can enable them on a per-translation-unit basis with
117      <literal>-D_GLIBCXX_CONCEPT_CHECKS</literal>.
118  </para>
119  
120  <para>
121    Please note that the upcoming C++ standard has first-class
122    support for template parameter constraints based on concepts in the core
123    language. This will obviate the need for the library-simulated concept
124    checking described above.
125  </para>
126
127 </chapter>
128
129 </part>