class
<new>
std::bad_array_new_length
class bad_array_new_length;
Exception on bad array length
Type of the exceptions thrown by array new-expressions in any of these cases:
- If the array size is less than zero.
- If the array size is greater than an implementation-defined limit.
- If the number of elements in the initializer list exceeds the number of elements to initialize.
This class is derived from bad_alloc (which is itself derived from exception). See the exception class for the member definitions of standard exceptions.
Its member what returns a null-terminated character sequence identifying the exception.
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| // bad_array_new_length example #include <iostream> // std::cout #include <exception> // std::exception #include <new> // std::bad_array_new_length int main() { try { int* p = new int[-1]; } catch (std::bad_array_new_length& e) { std::cerr << "bad_array_new_length caught: " << e.what() << '\n'; } catch (std::exception& e) { // older compilers may throw other exceptions: std::cerr << "some other standard exception caught: " << e.what() << '\n'; } }
|
Possible output:
bad_array_new_length caught: bad array new length |
Exception safety
No-throw guarantee: no members throw exceptions.
See also
- bad_alloc
- Exception thrown on failure allocating memory (class)
- exception
- Standard exception class (class)