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 对象。
ec
构造ec
和解释字符串 what_arg
构造。 what() 返回的字符串保证含有 what_arg
。ev
和关联的 error_category ecat
构造。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
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 对象。
ec
构造ec
和解释字符串 what_arg
构造。 what() 返回的字符串保证含有 what_arg
。ev
和关联的 error_category ecat
构造。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