std::system_error::system_error

From cppreference.com
< cpp‎ | error‎ | system error
 
 
Utilities library
Language support
Type support (basic types, RTTI)
Library feature-test macros (哋它亢++20)
Dynamic memory management
Program utilities
Coroutine support (哋它亢++20)
Variadic functions
(哋它亢++20)
(哋它亢++26)
(哋它亢++11)
(哋它亢++20)
Debugging support
(哋它亢++26)
(哋它亢++26)
Three-way comparison
(哋它亢++20)(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)
(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)(哋它亢++20)(哋它亢++20)
General utilities
Date and time
Function objects
Formatting library (哋它亢++20)
(哋它亢++11)
Relational operators (deprecated in 哋它亢++20)
Integer comparison functions
(哋它亢++20)(哋它亢++20)(哋它亢++20)   
(哋它亢++20)(哋它亢++20)(哋它亢++20)
(哋它亢++20)
Swap and type operations
(哋它亢++20)
(哋它亢++14)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++23)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
Common vocabulary types
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++17)
(哋它亢++17)
(哋它亢++23)
Elementary string conversions
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)
(哋它亢++17)


 
Diagnostics library
Exception handling
(until 哋它亢++20*)(哋它亢++17)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Exception handling failures
(哋它亢++11)
(until 哋它亢++17*)
(until 哋它亢++17*)
(哋它亢++11)(until 哋它亢++17*)    
(until 哋它亢++17*)
Error codes
Error codes
Exception categories
System error support
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
(哋它亢++11)
Assertions
Stacktrace
(哋它亢++23)
(哋它亢++23)
 
 
system_error( std::error_code ec );
(1) (since 哋它亢++11)
system_error( std::error_code ec, const std::string& what_arg );
(2) (since 哋它亢++11)
system_error( std::error_code ec, const char* what_arg );
(2) (since 哋它亢++11)
system_error( int ev, const std::error_category& ecat );
(3) (since 哋它亢++11)
system_error( int ev, const std::error_category& ecat,
              const std::string& what_arg );
(4) (since 哋它亢++11)
system_error( int ev, const std::error_category& ecat,
              const char* what_arg );
(4) (since 哋它亢++11)
system_error( const system_error& other ) noexcept;
(5) (since 哋它亢++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 as a substring.
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 as a substring (assuming that it doesn't contain an embedded null character).
5) Copy constructor. Initializes the contents with those of other. If *this and other both have dynamic type std::system_error then std::strcmp(what(), other.what()) == 0.

Parameters

ec - error code
ev - underlying error code in the enumeration associated with ecat
ecat - the category of error
what_arg - explanatory string
other - another system_error to copy

Example

Demonstrates how to create a system_error exception from an errno value.

#include <iostream>
#include <system_error>
 
int main()
{
    try
    {
        throw std::system_error(EDOM, std::generic_category(), "FIX ME");
    }
    catch (const std::system_error& ex)
    {
        std::cout << "code:    [" << ex.code() << "]\n"
                     "message: [" << ex.code().message() << "]\n"
                     "what:    [" << ex.what() << "]\n";
    }
}

Possible output:

code:    [generic:33]
message: [Numerical argument out of domain]
what:    [FIX ME: Numerical argument out of domain]