std::bad_alloc
提供: cppreference.com
| ヘッダ <new> で定義
|
||
| class bad_alloc; |
||
std::bad_alloc は記憶域確保の失敗を報告するために確保関数によって例外として投げられるオブジェクトの型です。
目次 |
[編集] メンバ関数
| コンストラクタ |
bad_alloc オブジェクトを構築します (パブリックメンバ関数) |
| operator= |
bad_alloc オブジェクトを置き換えます (パブリックメンバ関数) |
| what |
説明文字列を返します (パブリックメンバ関数) |
std::bad_alloc::bad_alloc
| bad_alloc() throw(); |
(C++11未満) | |
| bad_alloc() noexcept; |
(C++11以上) | |
what() を通してアクセス可能な処理系定義のNULL終端バイト文字列を持つ新しい bad_alloc オブジェクトを構築します。
引数
(なし)
std::bad_alloc::operator=
| bad_alloc& operator=( const bad_alloc& other ) throw(); |
(C++11未満) | |
| bad_alloc& operator=( const bad_alloc& other ) noexcept; |
(C++11以上) | |
other の内容を代入します。
引数
| other | - | 代入する別の例外オブジェクト |
戻り値
*this
std::bad_alloc::what
| virtual const char* what() const throw(); |
(C++11未満) | |
| virtual const char* what() const noexcept; |
(C++11以上) | |
説明文字列を返します。
引数
(なし)
戻り値
説明情報を持つNULL終端文字列へのポインタ。
std::exception から継承
メンバ関数
| [仮想] |
例外オブジェクトを破棄します ( std::exceptionの仮想パブリックメンバ関数)
|
| [仮想] |
説明文字列を返します ( std::exceptionの仮想パブリックメンバ関数)
|
[編集] 例
Run this code
#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
[編集] 関連項目
| 確保関数 (関数) |


