Exception.h File Reference
#include <string>
#include <buffy/stringf.h>
Go to the source code of this file.
|
Functions |
void | DefaultUnexpected () |
| This is an unexpected handler provided by the library.
|
Detailed Description
This file provides the root of the exception hierarchy. The goal of this hierarchy is to provide the most possible information on what caused the exception at the least possible cost for the programmer.
Every exception is the descendent of Exception that, in turn, extends the std::exception class of the STL.
Further descendents of Exception add functionality and automatisms to error message generation:
- ContextException extends Exception to provide informations on the context in which the exception was raised
- ConsistencyCheckException extends ContextException to be a base class for all exception raised on failure of a consistency check; IndexOutOfRangeException is one example of such exceptions, to be used when checking that a value (such as an index) fails betweed two given bounds.
- SystemException extends ContextException to carry informations about error conditions reported by external services, like the Operating System, a database interface or an interface used to communicate to some network server. In particular, it provides the logic needed to make use of the error descriptions provided by the external services, as strerror(3) does for the operating system's error conditions. FileException is an example of such exceptions, to be used to report error conditions happened during File I/O.
Example exception raising:
void MyFile::open(const char* fname) throw (FileException)
{
if ((fd = open(fname, O_RDONLY)) == -1)
throw FileException(errno, stringf::fmt("opening %s read-only", fname));
}
Example exception catching:
try {
myfile.open("/tmp/foo");
} catch (FileException& e) {
fprintf(stderr, "%.*s: aborting.\n", PFSTR(e.toString()));
exit(1);
}
Function Documentation
void DefaultUnexpected |
( |
|
) |
|
|
|
This is an unexpected handler provided by the library.
It prints to stderr a stack trace and all possible available informations about the escaped exception.
To have the function names in the stack trace, the executables need to be linked using the -rdynamic flag. |
Generated on Fri Mar 11 02:17:52 2005 for libbuffy by
1.4.1