The class error_code describes an object used to hold error code values, such as those originating from the operating system or other low-level application program interfaces. [ Note: Class error_code is an adjunct to error reporting by exception. — end note ]
namespace std { class error_code { public: // [syserr.errcode.constructors] constructors: error_code() noexcept; error_code(int val, const error_category& cat) noexcept; template <class ErrorCodeEnum> error_code(ErrorCodeEnum e) noexcept; // [syserr.errcode.modifiers] modifiers: void assign(int val, const error_category& cat) noexcept; template <class ErrorCodeEnum> error_code& operator=(ErrorCodeEnum e) noexcept; void clear() noexcept; // [syserr.errcode.observers] observers: int value() const noexcept; const error_category& category() const noexcept; error_condition default_error_condition() const noexcept; string message() const; explicit operator bool() const noexcept; private: int val_; // exposition only const error_category* cat_; // exposition only }; // [syserr.errcode.nonmembers] non-member functions: error_code make_error_code(errc e) noexcept; bool operator<(const error_code& lhs, const error_code& rhs) noexcept; template <class charT, class traits> basic_ostream<charT,traits>& operator<<(basic_ostream<charT,traits>& os, const error_code& ec); } // namespace std
Effects: Constructs an object of type error_code.
Postconditions: val_ == 0 and cat_ == &system_category().
error_code(int val, const error_category& cat) noexcept;
Effects: Constructs an object of type error_code.
Postconditions: val_ == val and cat_ == &cat.
template <class ErrorCodeEnum>
error_code(ErrorCodeEnum e) noexcept;
Effects: Constructs an object of type error_code.
Postconditions: *this == make_error_code(e).
Remarks: This constructor shall not participate in overload resolution unless is_error_code_enum<ErrorCodeEnum>::value is true.
void assign(int val, const error_category& cat) noexcept;
Postconditions: val_ == val and cat_ == &cat.
template <class ErrorCodeEnum>
error_code& operator=(ErrorCodeEnum e) noexcept;
Postconditions: *this == make_error_code(e).
Returns: *this.
Remarks: This operator shall not participate in overload resolution unless is_error_code_enum<ErrorCodeEnum>::value is true.
Postconditions: value() == 0 and category() == system_category().
Returns: val_.
const error_category& category() const noexcept;
Returns: *cat_.
error_condition default_error_condition() const noexcept;
Returns: category().default_error_condition(value()).
Returns: category().message(value()).
explicit operator bool() const noexcept;
Returns: value() != 0.
error_code make_error_code(errc e) noexcept;
Returns: error_code(static_cast<int>(e), generic_category()).
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
Returns: lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value().
template <class charT, class traits>
basic_ostream<charT,traits>&
operator<<(basic_ostream<charT,traits>& os, const error_code& ec);
Effects: os << ec.category().name() << ':' << ec.value().