HP aC++/HP C Programmer's Guide (B3901-90036; A.06.26; September 2011)

Calling unexpected
Unlike HP C++, in HP aC++, when an unexpected handler wants to exit through a throw,
it must throw an exception that is legal according to the exception specification that calls
unexpected(), unless that exception specification includes the predefined type
bad_exception. If it includes bad_exception, and the type thrown from the
unexpected handler is not in the exception specification, then the thrown object is replaced
by a bad_exception object and throw processing continues.
The following example is legal in HP C++ but not in HP aC++. You can make the example
legal by including the exception header and adding bad_exception to foo’s throw
specification. The catch(...) in main will then catch a bad_exception object. This
is the only legal way an unexpected-handler can rethrow the original exception.
// #include <exception> Needed to make the example legal.
void my_unexpected_handler() { throw; }
void foo() throw() {
// void foo() throw(bad_exception) { To make the example legal,
// replace the previous line
// of code with this line.
throw 1000;
}
int main() {
set_unexpected( my_unexpected_handler );
try {
foo();
}
catch(...) {
printf(fail - not legal in aCC\n);
}
return 0;
}
Following is an example, illegal because my_unexpected_handler rethrows an int.
A possible conversion is to throw &x instead, as this is a pointer to int and therefore
legal with respect to the original throw specification. Alternatively, you can add
bad_exception to the throw specification, as in the prior example.
int x = 1000;
void my_unexpected_handler() { throw; }
void foo() throw( int * ) {
throw 1000;
}
int main() {
Migration Considerations when Using Exception Handling 255