C++ Extensions (cppx) Documentation Internal Version
Main | Namespaces | Classes | NamespaceMembers | ClassMembers | Files

stdx::Exception Class Reference

This exception base class extends the standard library exception base class to include a string error message and stacked exceptions. Stacked exceptions allow one to catch an exception, rethrow a new exception and still maintain information about the original exception in the standard what message.

So an example error message might look like this:

 EInvalidInputFile : fileparser.cc(99) : Parser::Parse() : Error parsing input file
 EInvalidArg : bar.cc(34) : Bar::Bar() : Could not create Bar object from string
 ELowLevelException : file1.cc(56) : foo() : Could convert string to int
 

This essentially gives a trace of three exceptions which where throw leading to the final program abort. A user can see that there was some trouble converting a string to an int (possibly in the wrong format) and as a result the program could not create an object of type Bar. Ultimately the program was trying to parse some input file and could not due to this conversion error. The key advantage to this style of nested exceptions is that it means that a programmer doesn't have to catch, decode, and come up with a new error message to rethrow a new exception. Instead we just stack exceptions together ...

Todo:
We probably should add support for disabling exceptions. This could be done pretty easily by adding TRY/CATCH macros and using a macro for the base class of stdx::Exception.

Inheritance diagram for stdx::Exception:

Inheritance graph
[legend]
List of all members.

Public Methods

Related Functions

(Note that these are not member functions.)

Detailed Documentation

Constructor & Destructor Documentation

stdx::Exception::Exception const std::string &    msg
 

Default constructor creates an exception object with the give error message.

stdx::Exception::~Exception   throw ()
 

Default deconstructor.

Member Function Documentation

void stdx::Exception::addCausingExceptionInfo const stdx::Exception &    e
 

Add information for the exception which caused this exception to be thrown.

void stdx::Exception::setReducedMessage const std::string &    msg
 

Set the reduced message for reduced verboseness when reporting errors

const char* stdx::Exception::what   const throw ()
 

Return an error message. If extra information has been added with the addCausingExceptionInfo() member function, then what will return the sequence of caught and rethrown exceptions leading to the current exception.

const char* stdx::Exception::reduced_what   const throw ()
 

Similar to the what() member function, except that the file name, the function name, and the line number are not printed.

Friends And Related Function Documentation

STDX_THROW eName,
descript    [related]
 

This macro will instantiation and throw an exception of type exceptionname. The description argument can be any expression suitable for insertion into an output stream. The macro will also add appropriate file and line number information. So for example, the following code:

 STDX_THROW( myException, "Error with int value " << i );

Would result in the following output:

 myException : somefile.cc(56) : function() : Error with int value 2
 

STDX_RETHROW caughtException,
eName,
descript    [related]
 

This macro will throw a new exception assuming a different exception has already been caught. It will append information relating to the caught exception to the new exception using the stdx::Exception::addCausingExceptionInfo() member function.

STDX_ASSERT assertion    [related]
 

This macro will throw a special EAssert exception after adding the appropriate file and line information.



The documentation for this class was generated from the following file:
Generated on Mon Aug 15 21:43:09 2005 by Doxygen 1.2.13-20020210 written by Dimitri van Heesch © 1997-2002