Difference between revisions of "cpp/memory/new/bad alloc"
From cppreference.com
m (Shorten template names. Use {{lc}} where appropriate.) |
m (Update links.) |
||
Line 44: | Line 44: | ||
===See also=== | ===See also=== | ||
{{dsc begin}} | {{dsc begin}} | ||
− | {{dsc inc | cpp/memory/new/ | + | {{dsc inc | cpp/memory/new/dsc operator_new}} |
{{dsc end}} | {{dsc end}} | ||
Revision as of 22:12, 31 May 2013
Defined in header <new>
|
||
class bad_alloc : public std::exception; |
||
std::bad_alloc
is the type of the object thrown as exceptions by the allocation functions to report failure to allocate storage.
Inheritance diagram
Contents |
Member functions
constructs the bad_alloc object (public member function) | |
replaces a bad_alloc object (public member function) | |
returns explanatory string (public member function) |
Inherited from std::exception
Member functions
[virtual] |
destroys the exception object (virtual public member function of std::exception )
|
[virtual] |
returns an explanatory string (virtual public member function of std::exception )
|
Example
Run this code
#include <iostream> #include <new> int main() { try { while (true) { new int[100000000ul]; } } catch (const std::bad_alloc& e) { std::cout << "Allocation failed: " << e.what() << '\n'; } }
Output:
Allocation failed: std::bad_alloc
See also
allocation functions (function) |