dlr::common::Exception Class Reference

Base class for all exceptions thrown from code in namespace dlr. More...

#include <exception.h>

Inheritance diagram for dlr::common::Exception:
[legend]

List of all members.

Public Member Functions

 Exception (const char *message) throw ()
 This constructor sets the internal "what()" message.
 Exception (const char *message, const char *fileName, int lineNumber) throw ()
 This constructor builds the internal "what()" message using detailed information about the error.
 Exception (const char *message, const char *functionName, const char *fileName, int lineNumber) throw ()
 This constructor builds the internal "what()" message using detailed information about the failure.
 Exception (const Exception &source) throw ()
 The copy constructor deep copies its argument.
virtual ~Exception () throw ()
 Destructor.
virtual void addTrace (const char *message) throw ()
 This public method appends the provided text to the internal "trace()" message.
virtual const char * trace () const throw ()
 This public method returns a C-style string describing the accumulated trace information from the exception throw.
virtual const char * what () const throw ()
 This public method returns a C-style string describing the condition which caused the exception to be thrown.
virtual Exceptionoperator= (const Exception &source) throw ()
 The assignment operator deep copies its argument.

Protected Member Functions

 Exception (const char *message, const char *childClassName) throw ()
 This protected constructor is provided so that derived classes can easily personalize this->what() output.
 Exception (const char *message, const char *childClassName, const char *functionName, const char *fileName, int lineNumber) throw ()
 This protected constructor is provided so that derived classes can easily generate standardized this->what() output.

Protected Attributes

char m_message [DLR_EXCEPTION_MESSAGE_LENGTH]
 This protected member is a C-style string which holds a message describing the condition which caused the exception to be thrown.
char m_traceMessage [DLR_EXCEPTION_TRACE_REQUIRED_STACK_LEVELS *DLR_EXCEPTION_TRACE_MESSAGE_LENGTH]
 This protected member is a C-style string which holds the accumulated exception trace message.
size_t m_traceMessageIndex
 This protected member is used to keep track of how much of m_traceMessage has been filled with stack information.


Detailed Description

Base class for all exceptions thrown from code in namespace dlr.

Note that we _don't_ catch standard exceptions and re-throw. This means if you must handle every possibly exception from a routine in namespace dlr, you need to catch the standard exceptions as well, like this:

try { dlr::foo(); } catch(dlr::Exception& e) { // ... } catch {std::exception& e) { // ... }

Note that since dlr::Exception is derived from std::exception, you can omit the catch(dlr::Exception&) block and still catch everything, like this:

try { dlr::foo(); } catch {std::exception& e) { // ... }

Finally, note that dlr::Exception and its immediate subclasses use no dynamically allocated memory. Presumably this will pay off sometime.

Definition at line 316 of file exception.h.


Constructor & Destructor Documentation

dlr::common::Exception::Exception ( const char *  message  )  throw ()

This constructor sets the internal "what()" message.

The message should generally provide information about the test failure. For example: "Unable to acquire global lock file: /var/myApp/.lockFile"

Parameters:
message This argument is a C-style string specifying the text of the message.

Definition at line 106 of file exception.cpp.

References DLR_EXCEPTION_MESSAGE_LENGTH.

dlr::common::Exception::Exception ( const char *  message,
const char *  fileName,
int  lineNumber 
) throw ()

This constructor builds the internal "what()" message using detailed information about the error.

Parameters:
message This argument specifies a description of the failure.
fileName This argument specifies the name of the file in which the failure occurred.
lineNumber This argument specifies the line number at which the failure occurred.

Definition at line 120 of file exception.cpp.

References DLR_EXCEPTION_MESSAGE_LENGTH.

dlr::common::Exception::Exception ( const char *  message,
const char *  functionName,
const char *  fileName,
int  lineNumber 
) throw ()

This constructor builds the internal "what()" message using detailed information about the failure.

Parameters:
message This argument specifies a description of the failure.
functionName This argument specifies the name of the function in which the failure occurred.
fileName This argument specifies the name of the file in which the failure occurred.
lineNumber This argument specifies the line number at which the failure occurred.

Definition at line 135 of file exception.cpp.

References DLR_EXCEPTION_MESSAGE_LENGTH.

dlr::common::Exception::Exception ( const Exception source  )  throw ()

The copy constructor deep copies its argument.

Parameters:
source This argument is the class instance to be copied.

Definition at line 151 of file exception.cpp.

References DLR_EXCEPTION_MESSAGE_LENGTH, DLR_EXCEPTION_TRACE_MESSAGE_LENGTH, and DLR_EXCEPTION_TRACE_REQUIRED_STACK_LEVELS.

virtual dlr::common::Exception::~Exception (  )  throw () [inline, virtual]

Destructor.

Definition at line 379 of file exception.h.

dlr::common::Exception::Exception ( const char *  message,
const char *  childClassName 
) throw () [protected]

This protected constructor is provided so that derived classes can easily personalize this->what() output.

The what() message will be constructed by combining the two arguments, separated by the two character string ": ". If the childClassName argument is set to 0, the what() message will simply be copied from message. For example, calling the constructor like this:

dlr::Exception("My message.", "MyException")

results in the following what() message:

"MyException: My message."

Calling the constructor like this:

dlr::Exception("My message.", 0)

results in the following what() message:

"My message."

Parameters:
message This argument is a C-style string specifying the desired what() message.
childClassName This argument, if not equal to 0, specifies the name of the child class from which this constructor was called. This name will be prepended to the what message.

Definition at line 190 of file exception.cpp.

References DLR_EXCEPTION_MESSAGE_LENGTH.

dlr::common::Exception::Exception ( const char *  message,
const char *  childClassName,
const char *  functionName,
const char *  fileName,
int  lineNumber 
) throw () [protected]

This protected constructor is provided so that derived classes can easily generate standardized this->what() output.

The what() message will be constructed by combining all of the arguments in a visually pleasing way. The constructor might be called from a derived class like this:

dlr::Exception("My message.", "MyException", "myFunction(int)", "myFile.cc", 265)

Parameters:
message This argument is a C-style string specifying the desired what() message.
childClassName This argument, if not equal to 0, specifies the name of the child class from which this constructor was called. This name will be prepended to the what message.
functionName This argument specifies the name of the function from which the exception was thrown.
fileName This argument specifies the name of the source file defining the function from which the exception was thrown.
lineNumber This argument specifies the source line number at which the exception was thrown.

Definition at line 204 of file exception.cpp.

References DLR_EXCEPTION_MESSAGE_LENGTH.


Member Function Documentation

void dlr::common::Exception::addTrace ( const char *  message  )  throw () [virtual]

This public method appends the provided text to the internal "trace()" message.

Note that the trace message is shared between all dlr::Exception instances, so if you use the addTrace() method of more than one exception at once, the trace message can get garbled.

Parameters:
message This argument is a C-style string containing the text to be added.

Definition at line 230 of file exception.cpp.

References DLR_EXCEPTION_TRACE_MESSAGE_LENGTH, and DLR_EXCEPTION_TRACE_REQUIRED_STACK_LEVELS.

Exception & dlr::common::Exception::operator= ( const Exception source  )  throw () [virtual]

The assignment operator deep copies its argument.

Parameters:
source This argument specifies the Exception instance to be copied.
Returns:
The return value is a reference to *this.

Definition at line 170 of file exception.cpp.

References DLR_EXCEPTION_MESSAGE_LENGTH, DLR_EXCEPTION_TRACE_MESSAGE_LENGTH, and DLR_EXCEPTION_TRACE_REQUIRED_STACK_LEVELS.

virtual const char* dlr::common::Exception::trace (  )  const throw () [inline, virtual]

This public method returns a C-style string describing the accumulated trace information from the exception throw.

The value of this string is set using calls to the addTrace() method.

Returns:
The return value is a C-style string describing the condition which caused the exception to be thrown.

Definition at line 404 of file exception.h.

References m_traceMessage.

virtual const char* dlr::common::Exception::what (  )  const throw () [inline, virtual]

This public method returns a C-style string describing the condition which caused the exception to be thrown.

The value of this string is set during construction based on the provided constructor arguments.

Returns:
The return value is a C-style string describing the condition which caused the exception to be thrown.

Definition at line 416 of file exception.h.

References m_message.


Member Data Documentation

char dlr::common::Exception::m_message[DLR_EXCEPTION_MESSAGE_LENGTH] [protected]

This protected member is a C-style string which holds a message describing the condition which caused the exception to be thrown.

Definition at line 501 of file exception.h.

Referenced by what().

char dlr::common::Exception::m_traceMessage[DLR_EXCEPTION_TRACE_REQUIRED_STACK_LEVELS *DLR_EXCEPTION_TRACE_MESSAGE_LENGTH] [protected]

This protected member is a C-style string which holds the accumulated exception trace message.

Definition at line 509 of file exception.h.

Referenced by trace().

This protected member is used to keep track of how much of m_traceMessage has been filled with stack information.

Definition at line 516 of file exception.h.


The documentation for this class was generated from the following files:

Generated on Tue Nov 24 23:57:56 2009 for dlrCommon Utility Library by  doxygen 1.5.8