std::system_error:: system_error
From cppreference.net
<
cpp
|
error
|
system error
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Diagnostics library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::system_error
| Member functions | ||||
|
system_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
を部分文字列として含むことが保証されます(埋め込まれたnull文字を含まないことを前提とします)。
5)
コピーコンストラクタ。内容を
other
の内容で初期化する。
*
this
と
other
の両方が動的型
std::system_error
を持つ場合、
std::
strcmp
(
what
(
)
, other.
what
(
)
)
==
0
となる。
パラメータ
| ec | - | エラーコード |
| ev | - | ecat に関連付けられた列挙型の基盤となるエラーコード |
| ecat | - | エラーのカテゴリ |
| what_arg | - | 説明文字列 |
| other | - |
コピーする別の
system_error
|
例
system_error
例外を
errno
値から作成する方法を示します。
このコードを実行
#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]