Chapter 5.  Diagnostics

Table of Contents

Exceptions
API Reference
Adding Data to exception
Use of errno by the library
Concept Checking

Exceptions

API Reference

All exception objects are defined in one of the standard header files: exception, stdexcept, new, and typeinfo.

The base exception object is exception, located in exception. This object has no string member.

Derived from this are several classes that may have a string member: a full hierarchy can be found in the source documentation.

Full API details.

Adding Data to exception

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 hierarchy:

   struct My_Exception : public std::runtime_error
   {
     public:
       My_Exception (const string& whatarg)
	   : std::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
   };