#pragma operator_new (C++ only)
Category
Purpose
Determines whether the new and new[] operators throw an exception if the requested memory cannot be allocated.
This pragma is equivalent to the -qlanglvl=newexcp option.
Defaults
returnsnull
Parameters
- returnsnull
- If the memory requested by the new operator cannot be allocated, the compiler returns 0, the null pointer. Use this option for compatibility with versions of the XL C++ compiler previous to Visual C++ V6.0.
- throwsexception
- If the memory requested by the new operator cannot be allocated, the compiler throws a standard exception of type std::bad_alloc. Use this option in new applications, for conformance with the C++ standard.
Usage
The pragma can be specified only once in a source file. It must appear before any statements in the source file. This pragma takes precedence over the -qlanglvl=newexcp compiler option.
Restrictions
This pragma applies only to versions of the new operator that throw exceptions; it does not apply to the nothrow or empty throw versions of the new operator (for the prototypes of all the new operator versions, see the description of the <new> header in the Standard C++ Library Reference). It also does not apply to class-specific new operators, user-defined new operators, and new operators with placement arguments.
Related information
- Allocation and deallocation functions
- The new operator
- -qlanglvl
- The <new> header in the Standard C++ Library Reference



