std::system_error
STD:系统[医]误差
Defined in header | | |
---|---|---|
class system_error; | | (since C++11) |
std::system_error
是由各种库函数%28引发的异常类型--通常是与OS设施接口的函数,例如std::thread
%29当异常有关联时std::error_code
,可以报告。
二次
二次
继承图
成员函数
(constructor) | constructs the system_error object (public member function) |
---|---|
code | returns error code (public member function) |
what virtual | returns explanatory string (virtual public member function) |
继承自STD:例外
成员函数
(destructor) virtual | destructs the exception object (virtual public member function of std::exception) |
---|---|
what virtual | returns an explanatory string (virtual public member function of std::exception) |
例
二次
#include <thread>
#include <iostream>
#include <system_error>
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
二次
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。