namespace std {
class bad_alloc : public exception;
}
概要
何らかの理由で記憶域の動的確保に失敗するなど、get_new_handler()
がnullptr
を返した場合に投げられる例外。
メンバ関数
名前 | 説明 | 対応バージョン |
---|---|---|
(constructor) | コンストラクタ | |
(destructor) | デストラクタ | |
operator= |
代入演算子 | |
what |
エラー理由を取得する |
#include <iostream>
#include <new>
struct X {};
int main()
{
try {
X* x = new X();
}
catch (std::bad_alloc& e) {
// メモリ確保に失敗
std::cout << e.what() << std::endl;
}
}