C++ New Library - bad_array_new_length


Advertisements

Description

This is an exception on bad array length.

Following is the declaration for std::bad_array_new_length.

		
class bad_array_new_length;

Parameters

none

Return Value

none

Exceptions

No-throw guarantee − this member function never throws exceptions.

Data races

none

Example

In below example for std::bad_array_new_length.

#include <iostream>
#include <exception>
#include <new>

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) {
      std::cerr << "some other standard exception caught: " << e.what() << '\n';
   }
}

The output should be like this −

It will throw an exception error
new.htm
Advertisements