std::system_error
来自 cppreference.cn
定义于头文件 <system_error> |
||
class system_error; |
(C++11 起) | |
std::system_error
是各种库函数(通常是与操作系统功能交互的函数,例如 std::thread 的构造函数)在抛出异常时使用的类型,当异常具有关联的 std::error_code 且该错误代码可报告时,就会抛出此类型异常。
继承图
目录 |
[编辑] 成员函数
构造 system_error 对象(公共成员函数) | |
替换 system_error 对象(公共成员函数) | |
返回错误码 (公共成员函数) | |
[虚函数] |
返回解释字符串 (虚公共成员函数) |
继承自 std::exception
成员函数
[虚函数] |
销毁异常对象 ( std::exception 的虚公共成员函数) |
[虚函数] |
返回解释字符串 ( std::exception 的虚公共成员函数) |
[编辑] 示例
运行此代码
#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]