名前空間
変種
操作

std::system_error

From cppreference.com
< cpp‎ | error
 
 
ユーティリティライブラリ
言語サポート
型のサポート (基本型、RTTI)
ライブラリ機能検査マクロ (C++20)
プログラムユーティリティ
可変引数関数
コルーチンサポート (C++20)
契約サポート (C++26)
三方比較
(C++20)
(C++20)(C++20)(C++20)  
(C++20)(C++20)(C++20)

汎用ユーティリティ
関係演算子 (C++20で非推奨)
 
 
 
ヘッダー <system_error> で定義
class system_error;
(C++11以降)

std::system_error は、例外が報告可能な関連する std::error_code を持つ場合に、さまざまなライブラリ関数(通常はOS機能とインターフェースする関数、例:std::thread のコンストラクタ)によってスローされる例外の型です。

cpp/error/exceptioncpp/error/runtime errorstd-system error-inheritance.svg

継承図

目次

[編集] メンバ関数

system_error オブジェクトを構築します
(public member function) [[編集]]
system_error オブジェクトを置き換えます
(public member function) [[編集]]
エラーコードを返します。
(public member function) [[編集]]
[virtual]
説明文字列を返す
(virtual public member function) [[編集]]

std::exception から継承

メンバ関数

例外オブジェクトを破棄する
(std::exception の仮想 public メンバー関数) [編集]
[virtual]
説明文字列を返す
(std::exception の仮想 public メンバー関数) [編集]

[編集]

#include <iostream>
#include <system_error>
#include <thread>
 
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]
English 日本語 中文(简体) 中文(繁體)