42.2. Exception classes

The exception classes forma hierarchy with CException as the base class. CException provides a unified interface to all exceptions that allow you to get human readable messages and status information that can be processed by computers (e.g. for exception recovery).

All exceptions have the following member functions (virtual):

The example below shows the simplest handling of CException types. Note that the exception is caught by reference so that member functions retain their polymorphism.

Example 42-1. Catching CException and exiting


#include <Exception.h>
#include <iostream>
using namespace std;
...
try {
...
}
catch (CException& error) {
    cerr << err.ReasonText() << endl;
    exit(-1);
}
            

The example prints out a meaningful error message and exits the program.