std::system_error
來自 cppreference.com
定義於標頭檔案 <system_error> |
||
class system_error; |
(C++11 起) | |
std::system_error
是各種庫函式(通常是與作業系統功能互動的函式,例如 std::thread 的建構函式)在丟擲異常時使用的型別,當異常具有關聯的 std::error_code 且該錯誤程式碼可報告時,就會丟擲此型別異常。
繼承圖
目錄 |
[編輯] 成員函式
構造 system_error 物件(公共成員函式) | |
替換 system_error 物件(公共成員函式) | |
返回錯誤碼 (公共成員函式) | |
[虛擬函式] |
返回解釋字串 (虛公共成員函式) |
繼承自 std::exception
成員函式
[虛擬函式] |
銷燬異常物件 ( std::exception 的虛公共成員函式) |
[虛擬函式] |
返回解釋字串 ( std::exception 的虛公共成員函式) |
[編輯] 示例
執行此程式碼
#include <iostream> #include <system_error> #include <thread> int main() { try { std::thread().detach(); // attempt to detach a non-thread } catch(const std::system_error& e) { std::cout << "Caught system_error with code " "[" << e.code() << "] meaning " "[" << e.what() << "]\n"; } }
可能的輸出
Caught system_error with code [generic:22] meaning [Invalid argument]