[syserr.errcode] (original) (raw)
19 Diagnostics library [diagnostics]
19.5 System error support [syserr]
19.5.4 Class error_code [syserr.errcode]
19.5.4.1 Overview [syserr.errcode.overview]
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 1:
Class error_code is an adjunct to error reporting by exception.
— _end note_]
namespace std { class error_code { public: error_code() noexcept; error_code(int val, const error_category& cat) noexcept;template<class ErrorCodeEnum> error_code(ErrorCodeEnum e) noexcept;void assign(int val, const error_category& cat) noexcept;template<class ErrorCodeEnum> error_code& operator=(ErrorCodeEnum e) noexcept;void clear() noexcept;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_; const error_category* cat_; }; error_code make_error_code(errc e) noexcept;template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const error_code& ec);}
19.5.4.2 Constructors [syserr.errcode.constructors]
Effects: Initializes val_ with 0and cat_ with &system_category().
error_code(int val, const error_category& cat) noexcept;
Effects: Initializes val_ with valand cat_ with &cat.
template<class ErrorCodeEnum> error_code(ErrorCodeEnum e) noexcept;
Effects: Equivalent to:error_code ec = make_error_code(e); assign(ec.value(), ec.category());
19.5.4.3 Modifiers [syserr.errcode.modifiers]
void assign(int val, const error_category& cat) noexcept;
Postconditions: val_ == val and cat_ == &cat.
template<class ErrorCodeEnum> error_code& operator=(ErrorCodeEnum e) noexcept;
Effects: Equivalent to:error_code ec = make_error_code(e); assign(ec.value(), ec.category());
Postconditions: value() == 0 and category() == system_category().
19.5.4.4 Observers [syserr.errcode.observers]
int value() const noexcept;
const error_category& category() const noexcept;
error_condition default_error_condition() const noexcept;
Returns: category().default_error_condition(value()).
Returns: category().message(value()).
explicit operator bool() const noexcept;
19.5.4.5 Non-member functions [syserr.errcode.nonmembers]
error_code make_error_code(errc e) noexcept;
Returns: error_code(static_cast<int>(e), generic_category()).
template<class charT, class traits> basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
Effects: Equivalent to: return os << ec.category().name() << ':' << ec.value();