C++ Exception 库 - bad_alloc
描述
这是分配内存失败时抛出的异常。
声明
以下是 std::bad_alloc 的声明。
class bad_alloc;
C++11
class bad_alloc;
参数
none
返回值
none
异常
No-throw guarantee − 没有成员抛出异常。
示例
在下面的 std::bad_alloc 示例中。
#include <iostream>
#include <new>
int main () {
try {
int* myarray= new int[500000];
} catch (std::bad_alloc& ba) {
std::cerr << "bad_alloc caught: " << ba.what() << '\n';
}
return 0;
}

