std::bad_exception
From cppreference.com
| ヘッダー <exception> で定義 |
||
| class bad_exception; |
||
std::bad_exception は、C++ランタイムが以下の状況でスローする例外の型です。
|
(C++11以降) |
|
(C++17まで) |
継承図
|
|
(C++26以降) |
目次 |
[編集] メンバ関数
bad_exception オブジェクトを構築します。(public member function) | |
| オブジェクトをコピーします。 (public member function) | |
| [virtual] |
説明文字列を返す (仮想 public メンバ関数) |
std::exception から継承
メンバ関数
| [virtual] |
例外オブジェクトを破棄する ( std::exception の仮想 public メンバー関数) |
| [virtual] |
説明文字列を返す ( std::exception の仮想 public メンバー関数) |
[編集] 注記
| 機能テストマクロ | 値 | 規格 | 機能 |
|---|---|---|---|
__cpp_lib_constexpr_exceptions |
202411L |
(C++26) | constexpr for exception types |
[編集] 例
C++14 以前のモードでのみコンパイルされます(警告が発行される場合があります)。
このコードを実行
#include <exception> #include <iostream> #include <stdexcept> void my_unexp() { throw; } void test() throw(std::bad_exception) // Dynamic exception specifications // are deprecated in C++11 { throw std::runtime_error("test"); } int main() { std::set_unexpected(my_unexp); // Deprecated in C++11, removed in C++17 try { test(); } catch (const std::bad_exception& e) { std::cerr << "Caught " << e.what() << '\n'; } }
実行結果の例
Caught std::bad_exception