A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.com/reference/new/bad_array_new_length/ below:

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:

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 safetyNo-throw guarantee: no members throw exceptions.

See also
bad_alloc
Exception thrown on failure allocating memory (class)
exception
Standard exception class (class)

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4