std::bad_array_new_length
提供: cppreference.com
ヘッダ <new> で定義
|
||
class bad_array_new_length; |
(C++11以上) | |
std::bad_array_new_length
は以下の場合に無効な配列の長さを報告するため new 式によって例外として投げられるオブジェクトの型です。
1) 配列の長さが負
2) 配列の合計サイズが処理系定義の最大値を超過した
3) 初期化子節の数が初期化する要素の数を超過した
最初の配列次元のみがこの例外を生成し得ます。 最初以外の次元は定数式であり、コンパイル時にチェックされます。
目次 |
[編集] メンバ関数
bad_array_new_length オブジェクトを構築します (パブリックメンバ関数) |
std::bad_alloc から継承
std::exception から継承
メンバ関数
[仮想] |
例外オブジェクトを破棄します ( std::exception の仮想パブリックメンバ関数)
|
[仮想] |
説明文字列を返します ( std::exception の仮想パブリックメンバ関数)
|
[編集] ノート
仮想メンバ関数 what()
に対するオーバーライドが提供されるかもしれませんが、要求はされていません。
[編集] 例
std::bad_array_new_length
が投げられるべき3つの状況
Run this code
#include <iostream> #include <new> #include <climits> int main() { int negative = -1; int small = 1; int large = INT_MAX; try { new int[negative]; // negative size new int[small]{1,2,3}; // too many initializers new int[large][1000000]; // too large } catch(const std::bad_array_new_length &e) { std::cout << e.what() << '\n'; } }
出力例:
std::bad_array_new_length
[編集] 関連項目
確保関数 (関数) | |
メモリ確保が失敗したときに投げられる例外 (クラス) |