From cppreference.com
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
) when the exception has an associated
, which may be reported.
Inheritance diagram
Member functions
constructs the system_error object
(public member function)
replaces the system_error object
(public member function)
returns error code
(public member function)
[virtual]
returns an explanatory string
(virtual public member function)
Inherited from
Member functions
[virtual]
destroys the exception object
(virtual public member function of std::exception)
[virtual]
returns an explanatory string
(virtual public member function of std::exception)
Example
Run this code
#include<iostream>#include<system_error>#include<thread>intmain(){try{std::thread().detach();// attempt to detach a non-thread}catch(conststd::system_error&e){std::cout<<"Caught system_error with code ""["<<e.code()<<"] meaning ""["<<e.what()<<"]\n";}}Possible output:
Caught system_error with code [generic:22] meaning [Invalid argument]