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

std::system_error::system_error

system_error( std::error_code ec );

(1)

(since C++11)

system_error( std::error_code ec, const std::string& what_arg );

(2)

(since C++11)

system_error( std::error_code ec, const char* what_arg );

(2)

(since C++11)

system_error( int ev, const std::error_category& ecat );

(3)

(since C++11)

system_error( int ev, const std::error_category& ecat, const std::string& what_arg);

(4)

(since C++11)

system_error( int ev, const std::error_category& ecat, const char* what_arg);

(4)

(since C++11)

构造新的系统错误对象。

1%29构造错误代码ec

2%29构造错误代码ec和解释字符串what_arg.返回的字符串what()保证包含what_arg...

3%29构造,并带有基础错误代码ev和相关错误类别ecat...

4%29构造,并带有基础错误代码ev,关联错误类别ecat和解释字符串what_arg.返回的字符串what()保证包含what_arg...

参数

ec

-

error code

ev

-

error code in base encoding

ecat

-

the category of error

what_arg

-

explanatory string

演示如何创建系统。[医]从errno值中错误异常。

二次

代码语言:javascript
复制
#include <iostream>
#include <system_error>
 
int main()
{
    try
    {
        throw std::system_error(EDOM, std::generic_category());
    }
    catch (const std::system_error& error)
    {
        std::cout << "Error: " << error.code()
                  << " - " << error.code().message() << '\n';
    }
}

二次

可能的产出:

二次

代码语言:javascript
复制
Error: generic:33 - Numerical argument out of domain

二次

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

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

扫码关注腾讯云开发者

领取腾讯云代金券