定义于头文件
<new>
|
||
class bad_alloc;
|
||
std::bad_alloc
是分配函数作为异常抛出的对象类型,以报告存储分配失败。
目录 |
(构造函数)
|
构造 bad_alloc 对象 (公开成员函数) |
operator=
|
替换一个 bad_alloc 对象 (公开成员函数) |
what
|
返回解释性字符串 (公开成员函数) |
bad_alloc();
|
||
以实现定义的空终止字节字符串构造新的 bad_alloc
对象,字符串能通过 what() 访问。
(无)
(无) | (C++11 前) |
noexcept 规定:
noexcept
|
(C++11 起) |
bad_alloc& operator=( const bad_alloc& other );
|
||
以 other
的内容赋值。
other | - | 要赋值的另一异常对象 |
*this
(无) | (C++11 前) |
noexcept 规定:
noexcept
|
(C++11 起) |
virtual const char* what() const;
|
||
返回解释性字符串。
(无)
指向有解释性信息的空终止字符串的指针。
(无) | (C++11 前) |
noexcept 规定:
noexcept
|
(C++11 起) |
[虚]
|
析构该异常对象 ( std::exception 的虚公开成员函数)
|
[虚]
|
返回解释性字符串 ( 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'; } }
可能的输出:
Allocation failed: std::bad_alloc
分配函数 (函数) |