1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
4 <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
5 <META NAME="AUTHOR" CONTENT="pme@sources.redhat.com (Phil Edwards)">
6 <META NAME="KEYWORDS" CONTENT="HOWTO, libstdc++, GCC, g++, libg++, STL">
7 <META NAME="DESCRIPTION" CONTENT="HOWTO for the libstdc++ chapter 19.">
8 <META NAME="GENERATOR" CONTENT="vi and eight fingers">
9 <TITLE>libstdc++-v3 HOWTO: Chapter 19</TITLE>
10 <LINK REL=StyleSheet HREF="../lib3styles.css">
11 <!-- $Id: howto.html,v 1.2 2001/03/25 00:01:56 pme Exp $ -->
15 <H1 CLASS="centered"><A NAME="top">Chapter 19: Diagnostics</A></H1>
17 <P>Chapter 19 deals with program diagnostics, such as exceptions
18 and assertions. You know, all the things we wish weren't even
23 <!-- ####################################################### -->
27 <LI><A HREF="#1">Adding data to exceptions</A>
28 <LI><A HREF="#2">Exception class hierarchy diagram</A>
29 <LI><A HREF="#3">Concept checkers -- <STRONG>new and improved!</STRONG></A>
34 <!-- ####################################################### -->
36 <H2><A NAME="1">Adding data to exceptions</A></H2>
37 <P>The standard exception classes carry with them a single string as
38 data (usually describing what went wrong or where the 'throw' took
39 place). It's good to remember that you can add your own data to
40 these exceptions when extending the heirarchy:
43 using std::runtime_error;
44 struct My_Exception : public runtime_error
47 My_Exception (const string& whatarg)
48 : runtime_error(whatarg), e(errno), id(GetDataBaseID()) { }
49 int errno_at_time_of_throw() const { return e; }
50 DBID id_of_thing_that_threw() const { return id; }
53 DBID id; // some user-defined type
56 <P>Return <A HREF="#top">to top of page</A> or
57 <A HREF="../faq/index.html">to the FAQ</A>.
61 <H2><A NAME="2">Exception class hierarchy diagram</A></H2>
62 <P>The <A HREF="exceptions_hiearchy.pdf">diagram</A> is in PDF, or
63 at least it will be once it gets finished.
65 <P>Return <A HREF="#top">to top of page</A> or
66 <A HREF="../faq/index.html">to the FAQ</A>.
70 <H2><A NAME="3">Concept checkers -- <STRONG>new and improved!</STRONG></A></H2>
71 <P>Better taste! Less fat! Literally!</P>
72 <P>In 1999, SGI added <EM>concept checkers</EM> to their implementation
73 of the STL: code which checked the template parameters of
74 instantiated pieces of the STL, in order to insure that the parameters
75 being used met the requirements of the standard. For example,
76 the Standard requires that types passed as template parameters to
77 <TT>vector</TT> be "Assignable" (which means what you think
78 it means). The checking was done during compilation, and none of
79 the code was executed at runtime.
81 <P>Unfortunately, the size of the compiler files grew significantly
82 as a result. The checking code itself was cumbersome. And bugs
83 were found in it on more than one occasion.
85 <P>The primary author of the checking code, Jeremy Siek, had already
86 started work on a replcement implementation. The new code has been
87 formally reviewed and accepted into
88 <A HREF="http://www.boost.org/libs/concept_check/concept_check.htm">the
89 Boost libraries</A>, and we are pleased to incorporate it into the
92 <P>The new version imposes a much smaller space overhead on the generated
93 object file. The checks are also cleaner and easier to read and
96 <P>Concept checking can be disabled when you build your code, for example,
97 to save space during a production build. Just define (via -D or
98 #define) any of the macros
99 <TT>_GLIBCPP_NO_CONCEPT_CHECKS (yes, with the leading underscore),
100 <TT>_STL_NO_CONCEPT_CHECKS</TT> (also with the leading underscore),
101 or <TT>NDEBUG</TT>. The first macro is specifically for this
102 feature, the second is the disabling macro for the replaced SGI
103 version (some code may assume SGI's version is in use), and the third
104 is the usual macro to disable <TT>assert()</TT>, which is often turned
105 off for production builds.
108 <P>Return <A HREF="#top">to top of page</A> or
109 <A HREF="../faq/index.html">to the FAQ</A>.
113 <!-- ####################################################### -->
116 <P CLASS="fineprint"><EM>
117 Comments and suggestions are welcome, and may be sent to
118 <A HREF="mailto:libstdc++@gcc.gnu.org">the mailing list</A>.
119 <BR> $Id: howto.html,v 1.2 2001/03/25 00:01:56 pme Exp $