| Getting Started | Documentation | Glish | Learn More | Programming | Contact Us |
| Version 1.9 Build 803 |
|
One of the advantages of the C++ exception mechanism is that one can design a class hierarchy of exceptions. This results in an a great amount of flexibility. The reason for this is that one can catch whole groups of exceptions with one catch block, and then handle them as appropriate. One can also catch an exception with a specific handler, and the rethrow the exception so that it can be caught with a more general handler.
The root of the exception hierarchy is the class AipsError. This class must be the base class for all new exception hierarchies. All of the exceptions which are part of the aips++ kernel, IndexError, AllocError, etc., are derived from the AipsError. Thus, if one wished, all exceptions resulting from the aips++ kernel could be caught by one catch block which catches AipsErrors. Generally, it is a good practice to derive all exceptions for a given library from a library specific exception class, e.g. TableError, which is in turn derived from AipsError.
AipsError offers the const member function getMesg() which returns the message stored with the exception. It can be used as:
try {
...
} catch (AipsError& x) {
cerr << "Unexpected exception: " << x.getMesg() << endl;
}