std::system_error::system_error
來自 cppreference.com
< cpp | error | system_error
system_error( std::error_code ec ); |
(1) | (C++11 起) |
system_error( std::error_code ec, const std::string& what_arg ); |
(2) | (C++11 起) |
system_error( std::error_code ec, const char* what_arg ); |
(2) | (C++11 起) |
system_error( int ev, const std::error_category& ecat ); |
(3) | (C++11 起) |
system_error( int ev, const std::error_category& ecat, const std::string& what_arg ); |
(4) | (C++11 起) |
system_error( int ev, const std::error_category& ecat, const char* what_arg ); |
(4) | (C++11 起) |
system_error( const system_error& other ) noexcept; |
(5) | (C++11 起) |
構造新的系統錯誤物件。
1) 用錯誤碼 ec 構造。
3) 用底層錯誤碼 ev 和關聯的錯誤類別 ecat 構造。
5) 複製建構函式。用 other 的內容初始化。如果 *this 和 other 都具有動態型別
std::system_error
,則 std::strcmp(what(), other.what()) == 0。[編輯] 引數
ec | - | 錯誤碼 |
ev | - | 與 ecat 關聯的列舉中的底層錯誤碼 |
ecat | - | 錯誤類別 |
what_arg | - | 解釋性字串 |
其他 | - | 要複製的另一個 system_error |
[編輯] 示例
演示如何從 errno 值建立 system_error
異常。
執行此程式碼
#include <iostream> #include <system_error> int main() { try { throw std::system_error(EDOM, std::generic_category(), "FIX ME"); } catch (const std::system_error& ex) { std::cout << "code: [" << ex.code() << "]\n" "message: [" << ex.code().message() << "]\n" "what: [" << ex.what() << "]\n"; } }
可能的輸出
code: [generic:33] message: [Numerical argument out of domain] what: [FIX ME: Numerical argument out of domain]