< cpp‎ | error‎ | error code
Utilities library
General utilities
Date and time
Function objects
Formatting library (C++20)
Relational operators (deprecated in C++20)
Integer comparison functions
Swap and type operations
Common vocabulary types
Elementary string conversions
error_code() noexcept;
(1) (since C++11)
error_code( int ec, const error_category& ecat ) noexcept;
(2) (since C++11)
template< class ErrorCodeEnum >
error_code( ErrorCodeEnum e ) noexcept;
(3) (since C++11)

Constructs new error code.

1) Constructs error code with default value. Equivalent to error_code(0, std::system_category()).
2) Constructs error code with ec as the platform-dependent error code and ecat as the corresponding error category.
3) Constructs error code from an error code enum e. Equivalent to make_error_code(e), where make_error_code is found by argument-dependent lookup. This overload participates in overload resolution only if std::is_error_code_enum<ErrorCodeEnum>::value is true.

[edit] Parameters

ec - platform dependent error code to construct with
ecat - error category corresponding to ec
e - error code enum to construct with

[edit] Notes

The ADL-found make_error_code is intended to be used in the original proposal N2422, and used by all known implementations. However, the standard requires that only std::make_error_code overloads are considered. This is LWG issue 3629.

[edit] See also

constructs an std::errc error code
(function) [edit]
constructs an iostream error code
(function) [edit]
constructs a future error code
(function) [edit]