Exception Handling

Exception handling provides a standard mechanism for coding responses to run-time errors or exceptions.

Exception Handling is the Default

Exception handling is on by default. To turn it off, you must use the +noeh option.

CAUTION: If your executable throws no exceptions, object files compiled with and without the +noeh option can be mixed freely.

However, in an executable which throws exceptions (note that HP aC++ run-time libraries throw exceptions), you must be certain that no exception is thrown in your application which will unwind through a function compiled without the exception handling option turned on. In order to prevent this, the call graph for the program must never have calls from functions compiled without exception handling to functions compiled with exception handling (either direct calls or calls made through a callback mechanism). If such calls do exist, and an exception is thrown, the unwinding can cause:


Exception Handling in C++

Following is an overview of the elements of C++ exception handling:

Exception Handling as Defined by the ANSI/ISO C++ International Standard

The Standard C++ Library provides classes that C++ programs can use for reporting errors. These classes are defined in the header file <stdexcept> and described in the ANSI/ISO C++ International Standard.

For More Information


Exception Handling Example

The simple program shown here illustrates exception handling concepts. This program:

#include <stdexcept> #include <iostream.h> #include <string> void fx () { // details omited throw range_error(string("some info")); } void main ( ) { try { fx (); } catch (runtime_error& r) { // handle any kind of error, including range_error cout <<r.what() << '\n'; } }


Debugging Exception Handling

The HP WDB Debugger and the HP/DDE Debugger support C++ exception handling. For more information see the following:


Performance Considerations when using Exception Handling

HP aC++ exception handling has no significant performance impact at either compile-time nor run-time, if you are not using optimization. If you are using optimization, be aware of the following run-time performance implications: