std::bad_alloc
提供: cppreference.com
<tbody>
</tbody>

| ヘッダ <new> で定義
|
||
class bad_alloc; |
||
std::bad_alloc は記憶域確保の失敗を報告するために確保関数によって例外として投げられるオブジェクトの型です。
継承図
メンバ関数
| bad_alloc オブジェクトを構築します (パブリックメンバ関数) | |
| bad_alloc オブジェクトを置き換えます (パブリックメンバ関数) | |
| 説明文字列を返します (パブリックメンバ関数) |
std::bad_alloc::bad_alloc
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> bad_alloc() throw(); |
(C++11未満) | |
bad_alloc() noexcept; |
(C++11以上) | |
what() を通してアクセス可能な処理系定義のヌル終端バイト文字列を持つ新しい bad_alloc オブジェクトを構築します。
引数
(なし)
std::bad_alloc::operator=
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> 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
<tbody> </tbody> <tbody class="t-dcl-rev "> </tbody><tbody> </tbody> virtual const char* what() const throw(); |
(C++11未満) | |
virtual const char* what() const noexcept; |
(C++11以上) | |
説明文字列を返します。
引数
(なし)
戻り値
説明情報を持つヌル終端文字列へのポインタ。
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
関連項目
| 確保関数 (関数) |