std::system_error
来自 cppreference.cn
定义于头文件 <system_error> |
||
class system_error; |
(since 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]