HP aC++/HP C A.06.25 Programmer's Guide
void foo1() {
X* xp1 = new(nothrow())X; // returns 0 when creating a nothrow
// object, if space is not allocated
}
void foo2() {
X* xp2 = newX: // may throw bad_alloc
}
void main() {
try {
foo1();
foo2();
}
catch (bad_alloc) {
// code to handle bad_alloc
}
catch(...) {
// code to handle all other exceptions
}
}
Possible Differences when Exiting a Signal Handler
Behavior when exiting a signal handler through a throw may differ between the two
compilers.
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.
268 Migrating from HP C++ (cfront) to HP aC++