The C++ standard specifies that programmers can use an older version of new
that returns nullptr
upon failure. For this purpose, header <new>
defines object nothrow (of type nothrow_t
), which is used as follows:
double *ptr = new( nothrow ) double[ 50000000 ];
The preceding statement uses the version of new
that does not throw bad_alloc
exceptions (i.e., nothrow
) to allocate an array of 50,000,000 double
s.
Software Engineering Observation 17.7
To make programs more robust, use the version of new that throws bad_alloc exceptions on failure.
18.221.27.155