HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)
example and the previous exception handling example. In this case, the try keyword
comes before the function body’s opening brace, and the catch handler comes after the
function body’s closing brace.
#include <stdexcept>
#include <iostream.h>
#include <string>
void fx ()
{
// .......
throw range_error(string(“some info”));
}
int main ( )
try {
fx ();
}
catch (runtime_error& r) {
cout <<r.what() << ‘\n’; }
Function try blocks are sometimes necessary with class constructor destruction. A function
try block is the only means of ensuring that all exceptions thrown during the construction
of an object are caught within the constructor. For example,
A::A()
try
: _member(fx())
{
cout << _member << ‘\n’;
}
catch (runtime_error& r) {
cout <<r.what() << ‘\n’;
}
Note that the function try block ensures the exception thrown from the member initializer
is caught within the constructor.
Debugging Exception Handling
The HP WDB Debugger supports C++ exception handling. For more information refer
to HP WDB documentation at http://www.hp.com/go/wdb.
Performance Considerations
HP aC++ exception handling has no significant performance impact at compile time or
runtime.
Using Threads
The HP aC++ runtime environment supports multi-threaded applications. The following
HP aC++ libraries are thread-safe with the limitations cited below:
202 Exception Handling