A RetroSearch Logo

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

Search Query:

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

class

<new>

std::bad_alloc

Exception thrown on failure allocating memory


Type of the exceptions thrown by the standard definitions of operator new and operator new[] when they fail to allocate the requested storage space.

This class is 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
15
// bad_alloc example
#include <iostream>     // std::cout
#include <new>          // std::bad_alloc

int main () {
  try
  {
    int* myarray= new int[10000];
  }
  catch (std::bad_alloc& ba)
  {
    std::cerr << "bad_alloc caught: " << ba.what() << '\n';
  }
  return 0;
}

Possible output:
bad_alloc caught: bad allocation


Exception safetyNo-throw guarantee: no members throw exceptions.

See also
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