set_new_handler() — Register a function for set_new_handler()

Standards

Standards / Extensions C or C++ Dependencies
ISO/ANSI C++ C++ only  

Format

#include <new>

new_handler set_new_handler(new_handler ph) throw();

General description

The set_new_handler() function is part of the z/OS® XL C++ error handling mechanism. If you have registered a new-handler function with set_new_handler(), that new-handler function will be called by the new operator if it is unable to allocate storage. If you have not registered a new-handler function, the default behavior is for the new operator to return NULL.

The argument supplied to set_new_handler() is of type new_handler as defined in the header <new> (that is, a pointer to a function with a void return type and no arguments).

For C++ applications that are compiled NOXPLINK, the variable containing the address of the new handler function is statically bound with the executable. This means that each executable has its own new handler function which is shared only by the other functions that are linkedited as part of that executable. This is true even if multiple threads are using that same executable. This means that you cannot issue a set_new_handler() from within a non-XPLINK DLL if the new handler function is to be invoked outside of that DLL.

For C++ applications that are compiled XPLINK, the new handler function is truly global, so the DLL restriction is lifted. In a multithreaded environment consisting of XPLINK executables, the new handler function created by a call to set_new_handler() still applies to all threads in the (POSIX) process.

The required behavior of a new handler is to perform one of the following operations:
  • Make more storage available for allocation and then return.
  • Call either abort() or exit(int).
  • Throw an object of type bad_alloc.

Returned value

Returns a value of type new_handler. The function pointed to is the function that was previously called by the set_new_handler() function, or NULL if a new handler function was not established.

Refer to z/OS XL C/C++ Language Reference for more information about z/OS XL C++ error handling, including the new operator and the set_new_handler() functions.

Related information