std::system_error
来自 zh.cppreference.net
| 定义于头文件 <system_error>
|
||
class system_error;
|
(自C++11起) | |
std::system_error 是各种库函数抛出的异常类型(通常是与操作系统设施交互的函数,例如 std::thread)当异常有关联的 std::error_code,可以报告。
继承图
成员函数
构造
system_error
对象
(公开成员函数) |
|
替换
system_error
对象
(公开成员函数) |
|
|
返回错误码
(公开成员函数) |
|
|
[virtual]
|
返回说明性字符串
(虚公开成员函数) |
继承自 std:: exception
成员函数
|
[virtual]
|
销毁异常对象
(
std::exception
的虚公开成员函数)
|
|
[virtual]
|
返回解释性字符串
(
std::exception
的虚公开成员函数)
|
示例
运行此代码
#include <iostream> #include <system_error> #include <thread> int main() { try { std::thread().detach(); // 尝试分离非线程对象 } catch(const std::system_error& e) { std::cout << "捕获到 system_error,错误码 " "[" << e.code() << "] 含义 " "[" << e.what() << "]\n"; } }
可能的输出:
捕获到 system_error,错误码 [generic:22] 含义 [Invalid argument]