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) |
system_error( const system_error& other ) noexcept; | (5) | (since C++11) |
Constructs new system error object.
ec
ec and explanation string what_arg. The string returned by what() is guaranteed to contain what_arg as a substring.ev and associated error category ecat.ev, associated error category ecat and explanatory string what_arg. The string returned by what() is guaranteed to contain what_arg as a substring (assuming that it doesn't contain an embedded null character ).other. If *this and other both have dynamic type std::system_error then std::strcmp(what(), other.what()) == 0.| ec | - | error code |
| ev | - | underlying error code in the enumeration associated with ecat |
| ecat | - | the category of error |
| what_arg | - | explanatory string |
| other | - | another system_error to copy |
Demonstrates how to create a system_error exception from an errno value.
#include <iostream>
#include <system_error>
int main()
{
try
{
throw std::system_error(EDOM, std::generic_category(), "hello world");
}
catch (const std::system_error& ex)
{
std::cout << ex.code() << '\n';
std::cout << ex.code().message() << '\n';
std::cout << ex.what() << '\n';
}
}Possible output:
generic:33 Numerical argument out of domain hello world: Numerical argument out of domain
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
https://en.cppreference.com/w/cpp/error/system_error/system_error