名前空間
変種
操作

std::system_error

提供: cppreference.com
< cpp‎ | error
 
 
ユーティリティライブラリ
汎用ユーティリティ
日付と時間
関数オブジェクト
書式化ライブラリ (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)
 
エラー処理
例外処理
例外処理の失敗
(C++17未満)
(C++17未満)
(C++11)(C++17未満)
(C++17未満)
エラー番号
エラー番号
例外のカテゴリ
アサーション
システムエラー
(C++11)
(C++11)
system_error
(C++11)
 
 
ヘッダ <system_error> で定義
class system_error;
(C++11以上)

std::system_error は、様々なライブラリ関数 (一般的には OS の機能とやりとりする関数、例えば std::thread のコンストラクタなど) によって、報告されるかもしれない関連する std::error_code を持つ場合に、投げられる例外の型です。

cpp/error/exceptioncpp/error/runtime errorstd-system error-inheritance.svg
画像の詳細

継承図

目次

[編集] メンバ関数

system_error オブジェクトを構築します
(パブリックメンバ関数) [edit]
エラーコードを返します
(パブリックメンバ関数) [edit]
[仮想]
説明文字列を返します
(仮想パブリックメンバ関数) [edit]

std::exception から継承

メンバ関数

例外オブジェクトを破棄します
(std::exceptionの仮想パブリックメンバ関数) [edit]
[仮想]
説明文字列を返します
(std::exceptionの仮想パブリックメンバ関数) [edit]

[編集]

#include <thread>
#include <iostream>
#include <system_error>
 
int main()
{
    try {
        std::thread().detach(); // attempt to detach a non-thread
    } catch(const std::system_error& e) {
        std::cout << "Caught system_error with code " << e.code() 
                  << " meaning " << e.what() << '\n';
    }
}

出力:

Caught system_error with code generic:22 meaning Invalid argument