Public Member Functions |
| Exception (const Exception &right) |
| Create a copy of Exception right.
|
| Exception (const char *filename, unsigned long line, const Exception &cause, long code=0, const char *format=0,...) |
| Create a new Exception from a catched Exception cause.
|
| Exception (const char *filename, unsigned long line, long code, const char *format=0,...) |
| Create a new Exception that is identified by a specific code.
|
| Exception (const char *filename, unsigned long line, const char *format=0,...) |
| Create a new unspecific (runtime) Exception.
|
virtual | ~Exception () throw () |
| Deallocates the stored Exception cause.
|
virtual Exception & | append (const char *format, va_list argptr) |
| Append printf formatted text to the stored message.
|
virtual Exception * | clone () const |
| Create a clone of this Exception.
|
virtual Exception * | getCause () |
| The cause for this Exception, or 0 if this Exception is also the root cause.
|
virtual const Exception * | getCause () const |
| The cause for this Exception, or 0 if this Exception is also the root cause.
|
virtual long | getCode () const |
| The code that identifies the reason for this Exception.
|
virtual const char * | getFilename () const |
| The source filename where this Exception was raised.
|
virtual unsigned long | getLine () const |
| The source line where this Exception was raised.
|
virtual std::string & | getMessage () |
| The formatted message that describes the reason why this Exception was raised.
|
virtual const std::string & | getMessage () const |
| The const version of getMessage().
|
virtual const char * | getName () const |
| The class name of this Exception.
|
virtual Exception & | getRootCause () |
| The root cause of this Exception.
|
virtual const Exception & | getRootCause () const |
| The root cause of this Exception.
|
virtual Exception & | setCause (const Exception *cause) |
| Set a clone of cause as the cause for this Exception.
|
virtual Exception & | setCode (long code) |
| Set the code that identifies the reason for this Exception.
|
Exception & | operator= (const Exception &right) |
| Make this Exception a copy of the Exception right.
|
virtual std::string | toString () const |
| A string representation of this Exception together with all causes processed recursively.
|
virtual const char * | what () const throw () |
| Overwrites the inherited method from std::exception.
|
Static Public Member Functions |
static std::string | toString (long error) |
| A string representation for the system error code error.
|
Static Public Attributes |
static const long | NULL_POINTER = 998 |
static const long | UNEXPECTED_EOF = 999 |
static const long | RIFF_INVALID_FOURCC = 2000 |
static const long | AVI_INVALID_LENGTH = 2002 |
static const long | MICXX_MAX = 9999 |
An Exception is able to represent an error code, a message text and a stack of exception causes.
Examples
-
Throwing an unspecific (runtime) Exception
This is probably the most common scenario, where an unspecific exception is thrown somewhere within the code (maybe due to invalid parameters passed to a function call, or an object used in an invalid state etc.) throw Exception(__FILE__, __LINE__, "invalid argument: foo=%d", (signed) foo)
If the exception is thrown because of a specific system error, e.g. signaled by errno (or GetLastError()
on a Windows platform) you could pass an error description like
-
Throwing a specific Exception
If an application or library as its own set of error codes, you could pass them like #define FILE_NOT_OPEN 1000
...
throw Exception(__FILE__, __LINE__, FILE_NOT_OPEN, "file not open: %s", filename.c_str());
-
Rethrowing a catched Exception
If an Exception is catched it could be rethrown as the cause wrapped within either a new specific or unspecific Exception. This might end up in a chain of causes from the innermost root cause to the outermost cause that might finally be reported by the application. try
{
...
}
catch (const Exception & exception)
{
throw Exception(__FILE__, __LINE__, exception, FILE_NOT_OPEN,
"file not open: %s", filename.c_str());
}
-
__MICXXTRY__
and __MICXXEND__
Placing the two macros __MICXXTRY__
and __MICXXEND__
consistently around all code fragments that might potentially throw an Exception, it is very easy to record the whole path (call stack) from the location where an Exception was thrown up to the point where the exception is handled. This also works for any exception derived from std::exception and also for any other exception (althought the information is limited to the recorded path down to the point where the exception was thrown).
- Author:
- Norbert Klose
- Date:
- December, 2006