Namespaces
Variants
Views
Actions

std::system_error

From cppreference.com
 
 
 
 
Defined in header <system_error>
class system_error : public std::runtime_error;
(since C++11)

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.

Contents

[edit] Member functions

constructs the system_error object
(public member function)
returns the reported error code
(public member function)
[virtual]
returns the explanatory string
(virtual public member function)

Inherited from std::exception

Member functions

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

[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