In HP aC++, a try block begins following the first call after the try keyword. This conforms to the standard that a legal exception cannot be thrown prior to the first call. The current handlers of try block are considered candidates to catch the exception.

In HP C++ the try keyword defines the beginning of a try block.

In this situation, when a signal is taken while executing between the try keyword and the return point of the first call, a throw from the signal handler does not find the associated handlers as candidates for catching the exception.

Differences in setjmp/longjmp Behavior

Interoperability with setjmp/longjmp is not implemented.

The standard specifies that an implementation need not clean up objects whose lifetimes are shortened by a longjmp:

The function signature longjmp(jmp_buf jbuf, int val) has more restricted behavior in this International Standard. When automatic objects are destroyed by a thrown exception, transferring control to a destination point in the program, a call to longjmp(jbuf, val) at the throw point transfers control to the destination point results in undefined behavior.

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.

204 Migrating from HP C++ (cfront) to HP aC++