2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN"
3 "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd"
6 <chapter id="std.diagnostics" xreflabel="Diagnostics">
7 <?dbhtml filename="diagnostics.html"?>
22 <indexterm><primary>Diagnostics</primary></indexterm>
25 <sect1 id="std.diagnostics.exceptions" xreflabel="Exceptions">
26 <?dbhtml filename="exceptions.html"?>
27 <title>Exceptions</title>
29 <sect2 id="std.diagnostics.exceptions.hierarchy" xreflabel="Exception Classes">
30 <title>Exception Classes</title>
32 All exception objects are defined in one of the standard header
33 files: <filename>exception</filename>,
34 <filename>stdexcept</filename>, <filename>new</filename>, and
35 <filename>typeinfo</filename>.
39 The base exception object is <classname>exception</classname>,
40 located in <filename>exception</filename>. This object has no
41 <classname>string</classname> member.
45 Derived from this are several classes that may have a
46 <classname>string</classname> member: a full hierarchy can be
47 found in the <ulink url="http://gcc.gnu.org/onlinedocs/libstdc++/latest-doxygen/a00460.html">source documentation</ulink>.
51 <sect2 id="std.diagnostics.exceptions.data" xreflabel="Adding Data to Exceptions">
52 <title>Adding Data to Exceptions</title>
54 The standard exception classes carry with them a single string as
55 data (usually describing what went wrong or where the 'throw' took
56 place). It's good to remember that you can add your own data to
57 these exceptions when extending the hierarchy:
60 struct My_Exception : public std::runtime_error
63 My_Exception (const string& whatarg)
64 : std::runtime_error(whatarg), e(errno), id(GetDataBaseID()) { }
65 int errno_at_time_of_throw() const { return e; }
66 DBID id_of_thing_that_threw() const { return id; }
69 DBID id; // some user-defined type
76 <sect1 id="std.diagnostics.concept_checking" xreflabel="Concept Checking">
77 <title>Concept Checking</title>
79 In 1999, SGI added <quote>concept checkers</quote> to their
80 implementation of the STL: code which checked the template
81 parameters of instantiated pieces of the STL, in order to insure
82 that the parameters being used met the requirements of the
83 standard. For example, the Standard requires that types passed as
84 template parameters to <classname>vector</classname> be
85 "Assignable" (which means what you think it means). The
86 checking was done during compilation, and none of the code was
90 Unfortunately, the size of the compiler files grew significantly
91 as a result. The checking code itself was cumbersome. And bugs
92 were found in it on more than one occasion.
95 The primary author of the checking code, Jeremy Siek, had already
96 started work on a replacement implementation. The new code has been
97 formally reviewed and accepted into
98 <ulink url="http://www.boost.org/libs/concept_check/concept_check.htm">the
99 Boost libraries</ulink>, and we are pleased to incorporate it into the
103 The new version imposes a much smaller space overhead on the generated
104 object file. The checks are also cleaner and easier to read and
109 They are off by default for all versions of GCC.
110 They can be enabled at configure time with
111 <link linkend="manual.intro.setup.configure"><literal>--enable-concept-checks</literal></link>.
112 You can enable them on a per-translation-unit basis with
113 <literal>-D_GLIBCXX_CONCEPT_CHECKS</literal>.
117 Please note that the upcoming C++ standard has first-class
118 support for template parameter constraints based on concepts in the core
119 language. This will obviate the need for the library-simulated concept
120 checking described above.