std::system_error::system_error
From 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で構築します。
4) 基になるエラーコードev、関連するエラーカテゴリecat、および説明文字列what_argで構築します。what()によって返される文字列は、what_argを部分文字列として含むことが保証されています(埋め込みヌル文字が含まれていない場合)。
5) コピーコンストラクタ。otherの内容で初期化します。もし*thisとotherが両方とも動的型
std::system_errorを持つ場合、std::strcmp(what(), other.what()) == 0。[編集] パラメータ
| エラーコード | - | エラーコード |
| 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]