std::system_error::system_error - cppreference.com

##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::system_error::system_error

From cppreference.com
< cpp‎ | 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)

Constructs new system error object.

1) Constructs with error code `ec`
2) Constructs with error code `ec` and explanation string `what_arg`. The string returned by what() is guaranteed to contain `what_arg`.
3) Constructs with underlying error code `ev` and associated error category `ecat`.
4) Constructs with underlying error code `ev`, associated error category `ecat` and explanatory string `what_arg`. The string returned by what() is guaranteed to contain `what_arg`.

### [edit] Parameters

ec | - | error code
ev | - | error code in base encoding
ecat | - | the category of error
what_arg | - | explanatory string

### [edit] Example

Demonstrates how to create a system_error exception from a errno value

Run this code

    #include <iostream>
    #include <system_error>

    int main()
    {
        try
        {
            throw std::system_error(EDOM, std::system_category());
        }
        catch (const std::system_error& error)
        {
            std::cout << "Error: " << error.code()
                      << " - " << error.code().message() << '\n';
        }
    }

Output:

    Error: system:33 - Numerical argument out of domain

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/error/system_error/system_error&oldid=64307"