首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::system_error

Defined in header <system_error>

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)

二次

代码语言:javascript
复制
#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';
    }
}

二次

产出:

二次

代码语言:javascript
复制
Caught system_error with code generic:22 meaning Invalid argument

二次

代码语言:txt
复制
 © cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

扫码关注腾讯云开发者

领取腾讯云代金券