名前空間
変種
操作

std::system_error

提供: cppreference.com
< cpp‎ | error
 
 
ユーティリティライブラリ
 
 
 
ヘッダ <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