Namespaces
Variants
Views
Actions

std::system_error::system_error

From cppreference.com
< cpp‎ | error‎ | system error
Revision as of 15:01, 2 November 2012 by P12bot (Talk | contribs)

 
 
 
 
std::system_error
Member functions
system_error::system_error
 

Template:ddcl list begin <tr class="t-dcl ">

<td >
system_error( std::error_code ec );
</td>

<td > (1) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
system_error( std::error_code ec, const std::string& what_arg );
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
system_error( std::error_code ec, const char* what_arg );
</td>

<td > (2) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
system_error( int ev, const std::error_category& ecat
</td>

<td > (3) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

<td >
system_error( int ev, const std::error_category& ecat,
              const std::string& what_arg);
</td>

<td > (4) </td> <td > (since C++11) </td> </tr> <tr class="t-dcl ">

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

<td > (4) </td> <td > (since C++11) </td> </tr> Template:ddcl list end

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 Template:rlpf 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 Template:rlpf is guaranteed to contain what_arg.

Parameters

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

Example

Demonstrates how to create a system_error exception from a errno value

#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