名稱空間
變體
操作

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 構造。
2) 用錯誤碼 ec 和解釋字串 what_arg 構造。由 what() 返回的字串保證包含 what_arg 作為子字串。
3) 用底層錯誤碼 ev 和關聯的錯誤類別 ecat 構造。
4) 用底層錯誤碼 ev、關聯的錯誤類別 ecat 和解釋字串 what_arg 構造。由 what() 返回的字串保證包含 what_arg 作為子字串(假設它不包含嵌入的空字元)。
5) 複製建構函式。用 other 的內容初始化。如果 *thisother 都具有動態型別 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]