HP aC++/HP C A.06.25 Programmer's Guide
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:
Using Threads 213