std::bad_exception
來自 cppreference.com
定義於標頭檔案 <exception> |
||
class bad_exception; |
||
std::bad_exception
是 C++ 執行時在以下情況下丟擲的異常型別:
|
(C++11 起) |
|
(C++17 前) |
繼承圖
|
(C++26 起) |
目錄 |
[編輯] 成員函式
構造 bad_exception 物件(公開成員函式) | |
複製物件 (公開成員函式) | |
[虛擬函式] |
返回解釋字串 (虛公共成員函式) |
繼承自 std::exception
成員函式
[虛擬函式] |
銷燬異常物件 ( std::exception 的虛公共成員函式) |
[虛擬函式] |
返回解釋字串 ( std::exception 的虛公共成員函式) |
[編輯] 注意
特性測試宏 | 值 | 標準 | 特性 |
---|---|---|---|
__cpp_lib_constexpr_exceptions |
202411L |
(C++26) | 異常型別的 constexpr |
[編輯] 示例
僅在 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