C++ New 库 - bad_array_new_length
描述
这是错误数组长度的例外。
以下是 std::bad_array_new_length 的声明。
class bad_array_new_length;
参数
none
返回值
none
异常
No-throw guarantee − 这个成员函数从不抛出异常。
数据竞争
none
示例
在下面的 std::bad_array_new_length 示例中。
#include <iostream>
#include <exception>
#include <new>
int main() {
try {
int* p = new int[-1];
} catch (std::bad_array_new_length& e) {
std::cerr << "bad_array_new_length caught: " << e.what() << '\n';
} catch (std::exception& e) {
std::cerr << "some other standard exception caught: " << e.what() << '\n';
}
}
输出应该是这样的 −
It will throw an exception error

