std::exception
From cppreference.com
| ヘッダー <exception> で定義 |
||
| class exception; |
||
throw式を通じてエラーを処理するための一貫したインターフェースを提供します。
標準ライブラリによって生成される全ての例外は std::exception を継承します。
|
|
(C++26以降) |
目次 |
[編集] メンバ関数
| 例外オブジェクトを構築する (public member function) | |
| [virtual] |
例外オブジェクトを破棄する (仮想publicメンバ関数) |
| 例外オブジェクトをコピーする (publicメンバ関数) | |
| [virtual] |
説明文字列を返す (仮想publicメンバ関数) |
[編集] 標準例外の要件
std::exception から派生する各標準ライブラリクラス T は、以下に挙げる public アクセス可能なメンバ関数を持ち、それぞれは 例外で終了しない(C++11まで)例外を投げない例外仕様を持つ(C++11から)
- デフォルトコンストラクタ (他のコンストラクタが提供されていない場合)
- コピーコンストラクタ
- コピー代入演算子
コピーコンストラクタとコピー代入演算子は、以下の事後条件を満たします。
- 2つのオブジェクト lhs と rhs が両方とも動的型
Tを持ち、lhs が rhs のコピーである場合、std::strcmp(lhs.what(), rhs.what()) は 0 と等しい。
そのような各 T の what() メンバ関数は、std::exception::what() に指定された制約を満たします。
[編集] 標準例外
- range_error
- overflow_error
- underflow_error
- regex_error (C++11から)
- system_error (C++11から)
- ios_base::failure (C++11から)
- filesystem::filesystem_error (C++17から)
- tx_exception (TM TS)
- nonexistent_local_time (C++20から)
- ambiguous_local_time (C++20から)
- format_error (C++20から)
- bad_any_cast (C++17から)
- bad_optional_access (C++17から)
- bad_expected_access (C++23から)
- bad_weak_ptr (C++11から)
- bad_function_call (C++11から)
- bad_alloc
- bad_array_new_length (C++11から)
- bad_exception
- ios_base::failure (C++11まで)
- bad_variant_access (C++17から)
[編集] ノート
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_constexpr_exceptions |
202411L |
(C++26) | constexpr for exception types |
[編集] 欠陥報告
以下の動作変更を伴う欠陥報告が、以前に公開されたC++標準に遡って適用されました。
| DR | 適用対象 | 公開された動作 | 正しい動作 |
|---|---|---|---|
| LWG 471 | C++98 | std::exception から派生した標準ライブラリクラスには要件がなかった |
追加された |