std::system_error::system_error

system_error( std::error_code ec );
(1) (C++11 起)
system_error( std::error_code ec, const std::string& what_arg );
(2) (C++11 起)
system_error( std::error_code ec, const char* what_arg );
(2) (C++11 起)
system_error( int ev, const std::error_category& ecat );
(3) (C++11 起)
system_error( int ev, const std::error_category& ecat,
              const std::string& what_arg);
(4) (C++11 起)
system_error( int ev, const std::error_category& ecat,
              const char* what_arg);
(4) (C++11 起)

构造新的 system_error 对象。

1) 以 error_code ec 构造
2) 以 error_code ec 和解释字符串 what_arg 构造。 what() 返回的字符串保证含有 what_arg
3) 以底层错误码 ev 和关联的 error_category ecat 构造。
4) 以底层错误码 ev 、关联的 error_category ecat 和解释字符串 what_arg 构造。 what() 返回的字符串保证含有 what_arg

参数

ec - 错误码
ev - 基础编码的错误码
ecat - 错误类别
what_arg - 解释性字符串

示例

演示如何从一个 errno 值创建一个 system_error 异常

#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';
    }
}

可能的输出:

Error: generic:33 - Numerical argument out of domain

std::system_error::system_error

system_error( std::error_code ec );
(1) (C++11 起)
system_error( std::error_code ec, const std::string& what_arg );
(2) (C++11 起)
system_error( std::error_code ec, const char* what_arg );
(2) (C++11 起)
system_error( int ev, const std::error_category& ecat );
(3) (C++11 起)
system_error( int ev, const std::error_category& ecat,
              const std::string& what_arg);
(4) (C++11 起)
system_error( int ev, const std::error_category& ecat,
              const char* what_arg);
(4) (C++11 起)

构造新的 system_error 对象。

1) 以 error_code ec 构造
2) 以 error_code ec 和解释字符串 what_arg 构造。 what() 返回的字符串保证含有 what_arg
3) 以底层错误码 ev 和关联的 error_category ecat 构造。
4) 以底层错误码 ev 、关联的 error_category ecat 和解释字符串 what_arg 构造。 what() 返回的字符串保证含有 what_arg

参数

ec - 错误码
ev - 基础编码的错误码
ecat - 错误类别
what_arg - 解释性字符串

示例

演示如何从一个 errno 值创建一个 system_error 异常

#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';
    }
}

可能的输出:

Error: generic:33 - Numerical argument out of domain

版本历史

  • (当前 | 先前 2017年4月30日 (日) 07:17Fruderica讨论 | 贡献. . (1,887字节) (-1,039). . (撤销)
  • 当前 | 先前 2014年10月26日 (日) 16:45P12bot讨论 | 贡献 . . (2,926字节) (0). . (Fix some translations) (撤销)
  • 当前 | 先前 2013年7月2日 (二) 08:05P12bot讨论 | 贡献 . . (2,926字节) (-230). . (Use {{lc}}. Update links. Various fixes.) (撤销)
  • 当前 | 先前 2012年11月2日 (五) 14:02P12bot讨论 | 贡献 . . (3,156字节) (+345). . (r2.7.3) (机器人添加:de, en, es, fr, it, ja, pt, ru) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 10:37P12讨论 | 贡献 . . (2,811字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前 2012年10月26日 (五) 06:00TranslationBot讨论 | 贡献. . (2,811字节) (-60). . (Translated from the English version using Google Translate) (撤销)
  • 当前 | 先前 2012年10月25日 (四) 13:25P12讨论 | 贡献 . . (2,871字节) (0). . (1个修订: Translate from the English version) (撤销)
  • 当前 | 先前) 2012年10月25日 (四) 12:00TranslationBot讨论 | 贡献. . (2,871字节) (+2,871). . (Translated from the English version using Google Translate)