GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::system_error - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. system_error
  3. system_error

最終更新日時: 2026年10月03日 22時31分04秒 (JST)
Akira Takahashi が更新

履歴 編集

class
<system_error>

std::system_error(C++11)

namespace std {
  class system_error : public runtime_error;
}

概要

system_errorクラスは、OSのエラーを表現するerror_codeクラスのオブジェクトを包含した例外クラスである。

メンバ関数

名前 説明 対応バージョン
system_error(error_code ec, const string& what_arg);
system_error(error_code ec, const char* what_arg);
system_error(error_code ec);
system_error(int ev, const error_category& cat,
const string& what_arg);
system_error(int ev, const error_category& cat,
const char* what_arg);
system_error(int ev, const error_category& cat);
error_codeオブジェクト or エラー値 + エラーカテゴリとエラー理由の文字列からsystem_errorオブジェクトを生成する C++11
const error_code& code() const noexcept; 包含しているerror_codeオブジェクトへの参照を取得する C++11
virtual const char* what() const noexcept; メッセージを取得する メッセージ内容は実装依存だが、「what_arg + ": " + code().message()」という形式になると予想できる。 C++11

例

#include <iostream>
#include <system_error>
#include <string>

int main()
{
  try {
    std::error_code ec(static_cast<int>(std::errc::invalid_argument),
                       std::generic_category());

    throw std::system_error(ec, "system error!");
  }
  catch (std::system_error& e) {
    const std::error_code& ec = e.code();

    std::cout << ec.value() << std::endl;
    std::cout << e.what() << std::endl;
  }
}

出力例

22
system error!: Invalid argument

バージョン

言語

  • C++11

処理系

  • Clang: 9.0.1 ✅
  • GCC: 4.7.0 ✅
  • Visual C++: 2010 ✅

参照

  • LWG Issue 1103. system_error constructor postcondition overly strict
    • C++11で、コンストラクタの事後条件が「what()がwhat_argと完全一致すること」から「what()の戻り値がwhat_argを部分文字列として含むこと」へ緩和された。処理系はwhat()にエラーコードの説明を付加するため、完全一致は実装不可能だった
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.