Namespaces
Variants
Views
Actions

std::system_error

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

 
 
 
 

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

<td>
Defined in header <system_error>
</td>

<td></td> <td></td> <tr class="t-dcl ">

<td >
class system_error;
</td>

<td class="t-dcl-nopad"> </td> <td > (since C++11) </td> </tr> Template:ddcl list end

std::system_error is the type of the exception thrown by various library functions (typically the functions that interface with the OS facilities, e.g. the constructor of std::thread), when the exception has an associated std::error_code which needs to be reported.

cpp/error/exceptioncpp/error/runtime errorstd-system error-inheritance.svg
About this image

Inheritance diagram

Contents

Member functions

Template:cpp/error/system error/dcl list constructorTemplate:cpp/error/system error/dcl list codeTemplate:cpp/error/system error/dcl list what

Inherited from std::exception

Member functions

[virtual]
destructs the exception object
(virtual public member function of std::exception) [edit]
[virtual]
returns an explanatory string
(virtual public member function of std::exception) [edit]

Example

#include <thread>
#include <iostream>
#include <system_error>
 
int main()
{
    try {
        std::thread().detach(); // attempt to detach a non-thread
    } catch(const std::system_error& e) {
        std::cout << "Caught system_error with code " << e.code() 
                  << " meaning " << e.what() << '\n';
    }
}

Output:

Caught system_error with code generic:22 meaning Invalid argument