std:: system_error
From cppreference.net
C++
Utilities library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Diagnostics library
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
std::system_error
|
定义于头文件
<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]