std::system_error
在标头
<system_error> 定义 |
||
class system_error;
|
(C++11 起) | |
std::system_error
是多种库函数(通常是与 OS 设施交接的函数,例如 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]