# Chapter 19: Diagnostics

Chapter 19 deals with program diagnostics, such as exceptions and assertions. You know, all the things we wish weren't even necessary at all.

# Contents

- Adding data to exceptions
- Exception class hierarchy diagram
- Concept checkers -- new and improved!

## Adding data to exceptions

The standard exception classes carry with them a single string as data (usually describing what went wrong or where the 'throw' took place). It's good to remember that you can add your own data to these exceptions when extending the heirarchy:

       using std::runtime_error;
       struct My_Exception : public runtime_error
       {
         public:
           My_Exception (const string& whatarg)
               : runtime_error(whatarg), e(errno), id(GetDataBaseID()) { }
           int  errno_at_time_of_throw() const { return e; }
           DBID id_of_thing_that_threw() const { return id; }
         protected:
           int    e;
           DBID   id;     // some user-defined type
       };

Return to top of page or to the FAQ.

## Exception class hierarchy diagram

The diagram is in PDF, or at least it will be once it gets finished.

Return to top of page or to the FAQ.

## Concept checkers -- new and improved!

Better taste! Less fat! Literally!

In 1999, SGI added concept checkers to their implementation of the STL: code which checked the template parameters of instantiated pieces of the STL, in order to insure that the parameters being used met the requirements of the standard. For example, the Standard requires that types passed as template parameters to `vector` be "Assignable" (which means what you think it means). The checking was done during compilation, and none of the code was executed at runtime.

Unfortunately, the size of the compiler files grew significantly as a result. The checking code itself was cumbersome. And bugs were found in it on more than one occasion.

The primary author of the checking code, Jeremy Siek, had already started work on a replcement implementation. The new code has been formally reviewed and accepted into the Boost libraries, and we are pleased to incorporate it into the GNU C++ library.

The new version imposes a much smaller space overhead on the generated object file. The checks are also cleaner and easier to read and understand.

Right now they are off by default. More will be added once GCC 3.0 is released and we have time to revisit this topic.

Return to top of page or to the FAQ.

Comments and suggestions are welcome, and may be sent to the mailing list.
$Id: howto.html,v 1.1.4.2 2001/05/30 21:59:31 pme Exp $