Defined in header <new> | ||
---|---|---|
class bad_alloc; |
std::bad_alloc
is the type of the object thrown as exceptions by the allocation functions to report failure to allocate storage.
Inheritance diagram.
(constructor) | constructs the bad_alloc object (public member function) |
operator= | replaces a bad_alloc object (public member function) |
what | returns explanatory string (public member function) |
bad_alloc(); |
Constructs new bad_alloc
object with an implementation-defined null-terminated byte string which is accessible through what()
.
(none).
(none) | (until C++11) |
noexcept specification: noexcept | (since C++11) |
bad_alloc& operator=( const bad_alloc& other ); |
Assigns the contents of other
.
other | - | another exception object to assign |
*this
.
(none) | (until C++11) |
noexcept specification: noexcept | (since C++11) |
virtual const char* what() const; |
Returns the explanatory string.
(none).
Pointer to a null-terminated string with explanatory information.
(none) | (until C++11) |
noexcept specification: noexcept | (since C++11) |
[virtual] | destructs the exception object (virtual public member function of std::exception ) |
[virtual] | returns an explanatory string (virtual public member function of std::exception ) |
#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'; } }
Possible output:
Allocation failed: std::bad_alloc
allocation functions (function) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/memory/new/bad_alloc