名前空間
変種

std::system_error::system_error

提供: cppreference.com
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (C++20)
(C++11)
関係演算子 (C++20で非推奨)
整数比較関数
(C++20)
スワップと型操作
(C++14)
(C++11)
(C++11)
(C++11)
(C++17)
一般的な語彙の型
(C++11)
(C++17)
(C++17)
(C++17)
(C++17)

初等文字列変換
(C++17)
(C++17)
 
 
 
<tbody> </tbody>
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以上)

新しいシステムエラーオブジェクトを構築します。

1) エラーコード ec を使用して構築します。
2) エラーコード ec と説明文字列 what_arg を使用して構築します。 what() によって返される文字列は what_arg を部分文字列として含むことが保証されます。
3) ベースとなるエラーコード ev および関連するエラーカテゴリ ecat を使用して構築します。
4) ベースとなるエラーコード ev、関連するエラーカテゴリ ecat および説明文字列 what_arg を使用して構築します。 what() によって返される文字列は what_arg を部分文字列として含むことが保証されます。

引数

ec - エラーコード
ev - ecat に紐付く列挙の、ベースとなるエラーコード
ecat - エラーのカテゴリ
what_arg - 説明文字列

errno の値から system_error 例外を作成する方法をデモンストレーションします。

#include <iostream>
#include <system_error>

int main()
{
    try
    {
        throw std::system_error(EDOM, std::generic_category(), "hello world");
    }
    catch (const std::system_error& ex)
    {
        std::cout << ex.code() << '\n';
        std::cout << ex.code().message() << '\n';
        std::cout << ex.what() << '\n';
    }
}

出力例:

generic:33
Numerical argument out of domain
hello world: Numerical argument out of domain