HP aC++/HP C A.06.20 Programmer's Guide

Exception Handling is the Default
In HP aC++ exception handling is enabled by default. Use the +noeh option to disable
exception handling.
NOTE: With exception handling disabled, the keywords throw and try generate a
compiler error. The HP C++ (cfront) compiler, behaves differently; the default is
exception handling off. To turn it on, you must use the +eh option.
If your executable throws no exceptions, object files compiled with and without the
+noeh option can be mixed freely. However, in an executable that throws exceptions
(HP aC++ runtime libraries throw exceptions), you must be certain that no exception
is thrown in your application which will unwind through a function compiled without
the exception handling option turned on.
In order to prevent this, the call graph for the program must never have calls from
functions compiled without exception handling to functions compiled with exception
handling (either direct calls or calls made through a callback mechanism). If such calls
do exist, and an exception is thrown, the unwinding can cause:
non-destruction of local objects (including compiler generated temporaries)
memory leaks when destructors are not executed
runtime errors when no catch clause is found
Memory Allocation Failure and operator new
In HP aC++ programs, when either operator new ( ) or operator new [ ]
cannot obtain a block of storage, a bad_alloc exception results. This is required by
the ANSI/ISO C++ International Standard.
In HP C++, memory allocation failures return a null pointer (zero) to the caller of
operator new ().
To handle memory allocation failures in HP aC++ and to avoid a program abort, do
one of the following:
Write try or catch clauses to handle the bad_alloc exception.
Use the nothrow_t parameter to specify the type when calling operator new and
check for a null pointer.
Example:
operator new (size_t size, const nothrow_t &) throw();
operator new [] (size_t size, const nothrow_t &) throw();
.
.
.
#include <new.h>
#include <stdexcept>
class X{};
Migration Considerations when Using Exception Handling 265