std::system_error

定义于头文件 <system_error>
class system_error;
(C++11 起)

std::system_error 是多种库函数(通常是与 OS 设施交接的函数,例如 std::thread 的构造函数)在拥有关联于该异常的 std::error_code 时抛出的异常类型,同时可能报告该 std::error_code

cpp/error/exceptioncpp/error/runtime errorstd-system error-inheritance.svg
关于这幅图像

继承图

目录

成员函数

构造 system_error 对象
(公开成员函数)
返回错误码
(公开成员函数)
[虚]
返回解释性字符串
(虚公开成员函数)

继承自 std::exception

成员函数

析构该异常对象
(std::exception 的虚公开成员函数)
[虚]
返回解释性字符串
(std::exception 的虚公开成员函数)

示例

#include <thread>
#include <iostream>
#include <system_error>
 
int main()
{
    try {
        std::thread().detach(); // 试图脱附一个非线程
    } 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

版本历史

  • (当前 | 先前 2017年4月30日 (日) 08:10Fruderica讨论 | 贡献. . (1,153字节) (-475). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 17:45P12bot讨论 | 贡献 . . (1,628字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 09:05P12bot讨论 | 贡献 . . (1,628字节) (-95). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 15:06P12bot讨论 | 贡献 . . (1,723字节) (+241). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 11:37P12讨论 | 贡献 . . (1,482字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 07:00TranslationBot讨论 | 贡献. . (1,482字节) (-16). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 14:25P12讨论 | 贡献 . . (1,498字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 13:00TranslationBot讨论 | 贡献. . (1,498字节) (+1,498). . (Translated from the English version using Google Translate)