std::system_error
定义于头文件
<system_error> |
||
class system_error;
|
(C++11 起) | |
std::system_error
是多种库函数(通常是与 OS 设施交接的函数,例如 std::thread 的构造函数)在拥有关联于该异常的 std::error_code 时抛出的异常类型,同时可能报告该 std::error_code 。
继承图
成员函数
构造 system_error 对象(公开成员函数) |
|
替换 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