Merge from mainline (gomp-merge-2005-02-26).
[official-gcc.git] / libstdc++-v3 / docs / html / 19_diagnostics / howto.html
blob7bf44c641f0fcb08a8cf4b6fec689dfe3520f196
1 <?xml version="1.0" encoding="ISO-8859-1"?>
2 <!DOCTYPE html
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7 <head>
8 <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
9 <meta name="AUTHOR" content="pme@gcc.gnu.org (Phil Edwards)" />
10 <meta name="KEYWORDS" content="HOWTO, libstdc++, GCC, g++, libg++, STL" />
11 <meta name="DESCRIPTION" content="HOWTO for the libstdc++ chapter 19." />
12 <meta name="GENERATOR" content="vi and eight fingers" />
13 <title>libstdc++-v3 HOWTO: Chapter 19: Diagnostics</title>
14 <link rel="StyleSheet" href="../lib3styles.css" type="text/css" />
15 <link rel="Start" href="../documentation.html" type="text/html"
16 title="GNU C++ Standard Library" />
17 <link rel="Prev" href="../18_support/howto.html" type="text/html"
18 title="Library Support" />
19 <link rel="Next" href="../20_util/howto.html" type="text/html"
20 title="General Utilities" />
21 <link rel="Copyright" href="../17_intro/license.html" type="text/html" />
22 <link rel="Help" href="../faq/index.html" type="text/html" title="F.A.Q." />
23 </head>
24 <body>
26 <h1 class="centered"><a name="top">Chapter 19: Diagnostics</a></h1>
28 <p>Chapter 19 deals with program diagnostics, such as exceptions
29 and assertions. You know, all the things we wish weren't even
30 necessary at all.
31 </p>
34 <!-- ####################################################### -->
35 <hr />
36 <h1>Contents</h1>
37 <ul>
38 <li><a href="#1">Adding data to exceptions</a></li>
39 <li><a href="#2">Exception class hierarchy diagram</a></li>
40 <li><a href="#3">Concept checkers -- <strong>new and improved!</strong></a></li>
41 </ul>
43 <hr />
45 <!-- ####################################################### -->
47 <h2><a name="1">Adding data to exceptions</a></h2>
48 <p>The standard exception classes carry with them a single string as
49 data (usually describing what went wrong or where the 'throw' took
50 place). It's good to remember that you can add your own data to
51 these exceptions when extending the hierarchy:
52 </p>
53 <pre>
54 struct My_Exception : public std::runtime_error
56 public:
57 My_Exception (const string&amp; whatarg)
58 : std::runtime_error(whatarg), e(errno), id(GetDataBaseID()) { }
59 int errno_at_time_of_throw() const { return e; }
60 DBID id_of_thing_that_threw() const { return id; }
61 protected:
62 int e;
63 DBID id; // some user-defined type
65 </pre>
66 <p>Return <a href="#top">to top of page</a> or
67 <a href="../faq/index.html">to the FAQ</a>.
68 </p>
70 <hr />
71 <h2><a name="2">Exception class hierarchy diagram</a></h2>
72 <p>At one point we were going to make up a PDF of the exceptions
73 hierarchy, akin to the one done for the I/O class hierarchy.
74 Time was our enemy. Since then we've moved to Doxygen, which has
75 the useful property of not sucking. Specifically, when the source
76 code is changed, the diagrams are automatically brought up to date.
77 For the old way, we had to update the diagrams separately.
78 </p>
79 <p>There are several links to the Doxygen-generated pages from
80 <a href="../documentation.html">here</a>.
81 </p>
82 <p>Return <a href="#top">to top of page</a> or
83 <a href="../faq/index.html">to the FAQ</a>.
84 </p>
86 <hr />
87 <h2><a name="3">Concept checkers -- <strong>new and improved!</strong></a></h2>
88 <p>Better taste! Less fat! Literally!</p>
89 <p>In 1999, SGI added <em>concept checkers</em> to their implementation
90 of the STL: code which checked the template parameters of
91 instantiated pieces of the STL, in order to insure that the parameters
92 being used met the requirements of the standard. For example,
93 the Standard requires that types passed as template parameters to
94 <code>vector</code> be &quot;Assignable&quot; (which means what you think
95 it means). The checking was done during compilation, and none of
96 the code was executed at runtime.
97 </p>
98 <p>Unfortunately, the size of the compiler files grew significantly
99 as a result. The checking code itself was cumbersome. And bugs
100 were found in it on more than one occasion.
101 </p>
102 <p>The primary author of the checking code, Jeremy Siek, had already
103 started work on a replacement implementation. The new code has been
104 formally reviewed and accepted into
105 <a href="http://www.boost.org/libs/concept_check/concept_check.htm">the
106 Boost libraries</a>, and we are pleased to incorporate it into the
107 GNU C++ library.
108 </p>
109 <p>The new version imposes a much smaller space overhead on the generated
110 object file. The checks are also cleaner and easier to read and
111 understand.
112 </p>
113 <p>They are off by default for all versions of GCC from 3.0 to 3.4 (the
114 latest release at the time of writing).
115 They can be enabled at configure time with
116 <a href="../configopts.html"><code>--enable-concept-checks</code></a>.
117 You can enable them on a per-translation-unit basis with
118 <code>#define _GLIBCXX_CONCEPT_CHECKS</code> for GCC 3.4 and higher
119 (or with <code>#define _GLIBCPP_CONCEPT_CHECKS</code> for versions
120 3.1, 3.2 and 3.3).
121 </p>
122 <p>Return <a href="#top">to top of page</a> or
123 <a href="../faq/index.html">to the FAQ</a>.
124 </p>
126 <!-- ####################################################### -->
128 <hr />
129 <p class="fineprint"><em>
130 See <a href="../17_intro/license.html">license.html</a> for copying conditions.
131 Comments and suggestions are welcome, and may be sent to
132 <a href="mailto:libstdc++@gcc.gnu.org">the libstdc++ mailing list</a>.
133 </em></p>
136 </body>
137 </html>