[syserr]

# 19 Diagnostics library [[diagnostics]](./#diagnostics)

## 19.5 System error support [syserr]

### [19.5.1](#general) General [[syserr.general]](syserr.general)

[1](#general-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L620)

Subclause [syserr] describes components that the standard library and
C++ programs may use to report error conditions originating from
the operating system or other low-level application program interfaces[.](#general-1.sentence-1)

[2](#general-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L625)

Components described in [syserr] do not change the value oferrno ([[errno]](errno "19.4 Error numbers"))[.](#general-2.sentence-1)

*Recommended practice*: Implementations should leave the error states provided by other
libraries unchanged[.](#general-2.sentence-2)

### [19.5.2](#system.error.syn) Header <system_error> synopsis [[system.error.syn]](system.error.syn)

[ð](#header:%3csystem_error%3e)

#include <compare> // see [[compare.syn]](compare.syn "17.12.1 Header <compare> synopsis")namespace std {class error_category; const error_category& generic_category() noexcept; const error_category& system_category() noexcept; class error_code; class error_condition; class system_error; template<class T>struct [is_error_code_enum](#lib:is_error_code_enum "19.5.2 Header <system_­error> synopsis [system.error.syn]") : public false_type {}; template<class T>struct [is_error_condition_enum](#lib:is_error_condition_enum "19.5.2 Header <system_­error> synopsis [system.error.syn]") : public false_type {}; enum class [errc](#lib:errc "19.5.2 Header <system_­error> synopsis [system.error.syn]") { // freestanding address_family_not_supported, // EAFNOSUPPORT address_in_use, // EADDRINUSE address_not_available, // EADDRNOTAVAIL already_connected, // EISCONN argument_list_too_long, // E2BIG argument_out_of_domain, // EDOM bad_address, // EFAULT bad_file_descriptor, // EBADF bad_message, // EBADMSG broken_pipe, // EPIPE connection_aborted, // ECONNABORTED connection_already_in_progress, // EALREADY connection_refused, // ECONNREFUSED connection_reset, // ECONNRESET cross_device_link, // EXDEV destination_address_required, // EDESTADDRREQ device_or_resource_busy, // EBUSY directory_not_empty, // ENOTEMPTY executable_format_error, // ENOEXEC file_exists, // EEXIST file_too_large, // EFBIG filename_too_long, // ENAMETOOLONG function_not_supported, // ENOSYS host_unreachable, // EHOSTUNREACH identifier_removed, // EIDRM illegal_byte_sequence, // EILSEQ inappropriate_io_control_operation, // ENOTTY interrupted, // EINTR invalid_argument, // EINVAL invalid_seek, // ESPIPE io_error, // EIO is_a_directory, // EISDIR message_size, // EMSGSIZE network_down, // ENETDOWN network_reset, // ENETRESET network_unreachable, // ENETUNREACH no_buffer_space, // ENOBUFS no_child_process, // ECHILD no_link, // ENOLINK no_lock_available, // ENOLCK no_message, // ENOMSG no_protocol_option, // ENOPROTOOPT no_space_on_device, // ENOSPC no_such_device_or_address, // ENXIO no_such_device, // ENODEV no_such_file_or_directory, // ENOENT no_such_process, // ESRCH not_a_directory, // ENOTDIR not_a_socket, // ENOTSOCK not_connected, // ENOTCONN not_enough_memory, // ENOMEM not_supported, // ENOTSUP operation_canceled, // ECANCELED operation_in_progress, // EINPROGRESS operation_not_permitted, // EPERM operation_not_supported, // EOPNOTSUPP operation_would_block, // EWOULDBLOCK owner_dead, // EOWNERDEAD permission_denied, // EACCES protocol_error, // EPROTO protocol_not_supported, // EPROTONOSUPPORT read_only_file_system, // EROFS resource_deadlock_would_occur, // EDEADLK resource_unavailable_try_again, // EAGAIN result_out_of_range, // ERANGE state_not_recoverable, // ENOTRECOVERABLE text_file_busy, // ETXTBSY timed_out, // ETIMEDOUT too_many_files_open_in_system, // ENFILE too_many_files_open, // EMFILE too_many_links, // EMLINK too_many_symbolic_link_levels, // ELOOP value_too_large, // EOVERFLOW wrong_protocol_type, // EPROTOTYPE}; template<> struct is_error_condition_enum<errc> : true_type {}; // [[syserr.errcode.nonmembers]](#errcode.nonmembers "19.5.4.5 Non-member functions"), non-member functions 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); // [[syserr.errcondition.nonmembers]](#errcondition.nonmembers "19.5.5.5 Non-member functions"), non-member functions error_condition make_error_condition(errc e) noexcept; // [[syserr.compare]](#compare "19.5.6 Comparison operator functions"), comparison operator functionsbool operator==(const error_code& lhs, const error_code& rhs) noexcept; bool operator==(const error_code& lhs, const error_condition& rhs) noexcept; bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
 strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept;
 strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept; // [[syserr.hash]](#hash "19.5.7 System error hash support"), hash supporttemplate<class T> struct hash; template<> struct hash<error_code>; template<> struct hash<error_condition>; // [syserr], system error supporttemplate<class T>constexpr bool [is_error_code_enum_v](#lib:is_error_code_enum_v "19.5.2 Header <system_­error> synopsis [system.error.syn]") = [is_error_code_enum](#lib:is_error_code_enum "19.5.2 Header <system_­error> synopsis [system.error.syn]")<T>::value; template<class T>constexpr bool [is_error_condition_enum_v](#lib:is_error_condition_enum_v "19.5.2 Header <system_­error> synopsis [system.error.syn]") = [is_error_condition_enum](#lib:is_error_condition_enum "19.5.2 Header <system_­error> synopsis [system.error.syn]")<T>::value;}

[1](#system.error.syn-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L767)

The value of each enum errc enumerator is the same as
the value of the [<cerrno>](errno.general#header:%3ccerrno%3e "19.4.1 General [errno.general]") macro shown in the above synopsis[.](#system.error.syn-1.sentence-1)

Whether or not the [<system_error>](#header:%3csystem_error%3e "19.5.2 Header <system_­error> synopsis [system.error.syn]") implementation
exposes the [<cerrno>](errno.general#header:%3ccerrno%3e "19.4.1 General [errno.general]") macros is unspecified[.](#system.error.syn-1.sentence-2)

[2](#system.error.syn-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L773)

The [is_error_code_enum](#lib:is_error_code_enum "19.5.2 Header <system_­error> synopsis [system.error.syn]") and [is_error_condition_enum](#lib:is_error_condition_enum "19.5.2 Header <system_­error> synopsis [system.error.syn]") templates may be
specialized for program-defined types to indicate that such types are eligible
for class [error_code](#lib:error_code "19.5.4.1 Overview [syserr.errcode.overview]") and class [error_condition](#lib:error_condition "19.5.5.1 Overview [syserr.errcondition.overview]") implicit
conversions, respectively[.](#system.error.syn-2.sentence-1)

### [19.5.3](#errcat) Class error_category [[syserr.errcat]](syserr.errcat)

#### [19.5.3.1](#errcat.overview) Overview [[syserr.errcat.overview]](syserr.errcat.overview)

[1](#errcat.overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L783)

The class error_category serves as a base class for types used
to identify the source and encoding of a particular category of error code[.](#errcat.overview-1.sentence-1)

Classes may be derived from error_category to support
categories of errors in addition to those defined in this document[.](#errcat.overview-1.sentence-2)

Such classes shall behave as specified in subclause [[syserr.errcat]](#errcat "19.5.3 Class error_­category")[.](#errcat.overview-1.sentence-3)

[*Note [1](#errcat.overview-note-1)*:

error_category objects are
passed by reference, and two such objects
are equal if they have the same address[.](#errcat.overview-1.sentence-4)

If there is more than a single object of a custom error_category type,
such equality comparisons can evaluate to false even for objects holding the same value[.](#errcat.overview-1.sentence-5)

â *end note*]

[ð](#lib:error_category_)

namespace std {class error_category {public:constexpr error_category() noexcept; virtual ~error_category();
 error_category(const error_category&) = delete;
 error_category& operator=(const error_category&) = delete; virtual const char* name() const noexcept = 0; virtual error_condition default_error_condition(int ev) const noexcept; virtual bool equivalent(int code, const error_condition& condition) const noexcept; virtual bool equivalent(const error_code& code, int condition) const noexcept; virtual string message(int ev) const = 0; bool operator==(const error_category& rhs) const noexcept;
 strong_ordering operator<=>(const error_category& rhs) const noexcept; }; const error_category& [generic_category](#lib:generic_category "19.5.3.5 Error category objects [syserr.errcat.objects]")() noexcept; const error_category& [system_category](#lib:system_category "19.5.3.5 Error category objects [syserr.errcat.objects]")() noexcept;}

#### [19.5.3.2](#errcat.virtuals) Virtual members [[syserr.errcat.virtuals]](syserr.errcat.virtuals)

[ð](#lib:name,error_category)

`virtual const char* name() const noexcept = 0;
`

[1](#errcat.virtuals-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L832)

*Returns*: A string naming the error category[.](#errcat.virtuals-1.sentence-1)

[ð](#lib:default_error_condition,error_category)

`virtual error_condition default_error_condition(int ev) const noexcept;
`

[2](#errcat.virtuals-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L843)

*Returns*: error_condition(ev, *this)[.](#errcat.virtuals-2.sentence-1)

[ð](#lib:equivalent,error_category)

`virtual bool equivalent(int code, const error_condition& condition) const noexcept;
`

[3](#errcat.virtuals-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L854)

*Returns*: default_error_condition(code) == condition[.](#errcat.virtuals-3.sentence-1)

[ð](#lib:equivalent,error_category_)

`virtual bool equivalent(const error_code& code, int condition) const noexcept;
`

[4](#errcat.virtuals-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L865)

*Returns*: *this == code.category() && code.value() == condition[.](#errcat.virtuals-4.sentence-1)

[ð](#lib:message,error_category)

`virtual string message(int ev) const = 0;
`

[5](#errcat.virtuals-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L876)

*Returns*: A string that describes the error condition denoted by ev[.](#errcat.virtuals-5.sentence-1)

#### [19.5.3.3](#errcat.nonvirtuals) Non-virtual members [[syserr.errcat.nonvirtuals]](syserr.errcat.nonvirtuals)

[ð](#lib:operator==,error_category)

`bool operator==(const error_category& rhs) const noexcept;
`

[1](#errcat.nonvirtuals-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L889)

*Returns*: this == &rhs[.](#errcat.nonvirtuals-1.sentence-1)

[ð](#lib:operator%3c=%3e,error_category)

`strong_ordering operator<=>(const error_category& rhs) const noexcept;
`

[2](#errcat.nonvirtuals-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L900)

*Returns*: compare_three_way()(this, &rhs)[.](#errcat.nonvirtuals-2.sentence-1)

[*Note [1](#errcat.nonvirtuals-note-1)*:

compare_three_way ([[comparisons.three.way]](comparisons.three.way "22.10.8.8 Class compare_­three_­way")) provides a total ordering for pointers[.](#errcat.nonvirtuals-2.sentence-2)

â *end note*]

#### [19.5.3.4](#errcat.derived) Program-defined classes derived from error_category [[syserr.errcat.derived]](syserr.errcat.derived)

[ð](#lib:name,error_category_)

`virtual const char* name() const noexcept = 0;
`

[1](#errcat.derived-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L917)

*Returns*: A string naming the error category[.](#errcat.derived-1.sentence-1)

[ð](#lib:default_error_condition,error_category_)

`virtual error_condition default_error_condition(int ev) const noexcept;
`

[2](#errcat.derived-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L928)

*Returns*: An object of type error_condition that corresponds to ev[.](#errcat.derived-2.sentence-1)

[ð](#lib:equivalent,error_category__)

`virtual bool equivalent(int code, const error_condition& condition) const noexcept;
`

[3](#errcat.derived-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L939)

*Returns*: true if, for the category of error represented by *this, code is considered equivalent to condition; otherwise, false[.](#errcat.derived-3.sentence-1)

[ð](#lib:equivalent,error_category___)

`virtual bool equivalent(const error_code& code, int condition) const noexcept;
`

[4](#errcat.derived-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L950)

*Returns*: true if, for the category of error represented by *this, code is considered equivalent to condition; otherwise, false[.](#errcat.derived-4.sentence-1)

#### [19.5.3.5](#errcat.objects) Error category objects [[syserr.errcat.objects]](syserr.errcat.objects)

[ð](#lib:generic_category_)

`const error_category& generic_category() noexcept;
`

[1](#errcat.objects-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L963)

*Returns*: A reference to an object of a type derived from class error_category[.](#errcat.objects-1.sentence-1)

All calls to this function shall return references to the same object[.](#errcat.objects-1.sentence-2)

[2](#errcat.objects-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L968)

*Remarks*: The object's default_error_condition and equivalent virtual functions shall behave as specified for the class error_category[.](#errcat.objects-2.sentence-1)

The object's name virtual function shall return a pointer to the string "generic"[.](#errcat.objects-2.sentence-2)

[ð](#lib:system_category_)

`const error_category& system_category() noexcept;
`

[3](#errcat.objects-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L979)

*Returns*: A reference to an object of a type derived from class error_category[.](#errcat.objects-3.sentence-1)

All calls to this function shall return references to the same object[.](#errcat.objects-3.sentence-2)

[4](#errcat.objects-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L984)

*Remarks*: The object's equivalent virtual functions shall behave as specified for
class error_category[.](#errcat.objects-4.sentence-1)

The object's name virtual function shall return a
pointer to the string "system"[.](#errcat.objects-4.sentence-2)

The object's default_error_condition virtual function shall behave as follows:

If the argument ev is equal to 0,
the function returns error_condition(0, generic_category())[.](#errcat.objects-4.sentence-4)

Otherwise,
if ev corresponds to a POSIX errno value pxv,
the function returns error_condition(pxv, generic_category())[.](#errcat.objects-4.sentence-5)

Otherwise, the function returns error_condition(ev, system_category())[.](#errcat.objects-4.sentence-6)

What constitutes correspondence for any given operating system is unspecified[.](#errcat.objects-4.sentence-7)

[*Note [1](#errcat.objects-note-1)*:

The number of potential system error codes is large
and unbounded, and some might not correspond to any POSIX errno value[.](#errcat.objects-4.sentence-8)

Thus
implementations are given latitude in determining correspondence[.](#errcat.objects-4.sentence-9)

â *end note*]

### [19.5.4](#errcode) Class error_code [[syserr.errcode]](syserr.errcode)

#### [19.5.4.1](#errcode.overview) Overview [[syserr.errcode.overview]](syserr.errcode.overview)

[1](#errcode.overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1009)

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[.](#errcode.overview-1.sentence-1)

[*Note [1](#errcode.overview-note-1)*:

Class error_code is an
adjunct to error reporting by exception[.](#errcode.overview-1.sentence-2)

â *end note*]

[ð](#lib:error_code_)

namespace std {class error_code {public:// [[syserr.errcode.constructors]](#errcode.constructors "19.5.4.2 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]](#errcode.modifiers "19.5.4.3 Modifiers"), modifiersvoid assign(int val, const error_category& cat) noexcept; template<class ErrorCodeEnum> error_code& operator=(ErrorCodeEnum e) noexcept; void clear() noexcept; // [[syserr.errcode.observers]](#errcode.observers "19.5.4.4 Observers"), observersint 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]](#errcode.nonmembers "19.5.4.5 Non-member functions"), non-member functions 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](#errcode.constructors) Constructors [[syserr.errcode.constructors]](syserr.errcode.constructors)

[ð](#lib:error_code,constructor)

`error_code() noexcept;
`

[1](#errcode.constructors-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1064)

*Effects*: Initializes *val_* with 0 and *cat_* with &system_category()[.](#errcode.constructors-1.sentence-1)

[ð](#lib:error_code,constructor_)

`error_code(int val, const error_category& cat) noexcept;
`

[2](#errcode.constructors-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1076)

*Effects*: Initializes *val_* with val and *cat_* with &cat[.](#errcode.constructors-2.sentence-1)

[ð](#lib:error_code,constructor__)

`template<class ErrorCodeEnum>
  error_code(ErrorCodeEnum e) noexcept;
`

[3](#errcode.constructors-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1089)

*Constraints*: [is_error_code_enum_v](#lib:is_error_code_enum_v "19.5.2 Header <system_­error> synopsis [system.error.syn]")<ErrorCodeEnum> is true[.](#errcode.constructors-3.sentence-1)

[4](#errcode.constructors-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1093)

*Effects*: Equivalent to:error_code ec = make_error_code(e);
assign(ec.value(), ec.category());

#### [19.5.4.3](#errcode.modifiers) Modifiers [[syserr.errcode.modifiers]](syserr.errcode.modifiers)

[ð](#lib:assign,error_code)

`void assign(int val, const error_category& cat) noexcept;
`

[1](#errcode.modifiers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1110)

*Postconditions*: *val_* == val and *cat_* == &cat[.](#errcode.modifiers-1.sentence-1)

[ð](#lib:operator=,error_code)

`template<class ErrorCodeEnum>
  error_code& operator=(ErrorCodeEnum e) noexcept;
`

[2](#errcode.modifiers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1122)

*Constraints*: [is_error_code_enum_v](#lib:is_error_code_enum_v "19.5.2 Header <system_­error> synopsis [system.error.syn]")<ErrorCodeEnum> is true[.](#errcode.modifiers-2.sentence-1)

[3](#errcode.modifiers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1126)

*Effects*: Equivalent to:error_code ec = make_error_code(e);
assign(ec.value(), ec.category());

[4](#errcode.modifiers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1134)

*Returns*: *this[.](#errcode.modifiers-4.sentence-1)

[ð](#lib:clear,error_code)

`void clear() noexcept;
`

[5](#errcode.modifiers-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1145)

*Postconditions*: value() == 0 and category() == system_category()[.](#errcode.modifiers-5.sentence-1)

#### [19.5.4.4](#errcode.observers) Observers [[syserr.errcode.observers]](syserr.errcode.observers)

[ð](#lib:value,error_code)

`int value() const noexcept;
`

[1](#errcode.observers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1159)

*Returns*: *val_*[.](#errcode.observers-1.sentence-1)

[ð](#lib:category,error_code)

`const error_category& category() const noexcept;
`

[2](#errcode.observers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1170)

*Returns*: **cat_*[.](#errcode.observers-2.sentence-1)

[ð](#lib:default_error_condition,error_code)

`error_condition default_error_condition() const noexcept;
`

[3](#errcode.observers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1181)

*Returns*: category().default_error_condition(value())[.](#errcode.observers-3.sentence-1)

[ð](#lib:message,error_code)

`string message() const;
`

[4](#errcode.observers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1192)

*Returns*: category().message(value())[.](#errcode.observers-4.sentence-1)

[ð](#lib:operator_bool,error_code)

`explicit operator bool() const noexcept;
`

[5](#errcode.observers-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1203)

*Returns*: value() != 0[.](#errcode.observers-5.sentence-1)

#### [19.5.4.5](#errcode.nonmembers) Non-member functions [[syserr.errcode.nonmembers]](syserr.errcode.nonmembers)

[ð](#lib:make_error_code,errc)

`error_code make_error_code(errc e) noexcept;
`

[1](#errcode.nonmembers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1216)

*Returns*: error_code(static_cast<int>(e), generic_category())[.](#errcode.nonmembers-1.sentence-1)

[ð](#lib:operator%3c%3c,error_code)

`template<class charT, class traits>
  basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
`

[2](#errcode.nonmembers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1228)

*Effects*: Equivalent to: return os << ec.category().name() << ':' << ec.value();

### [19.5.5](#errcondition) Class error_condition [[syserr.errcondition]](syserr.errcondition)

#### [19.5.5.1](#errcondition.overview) Overview [[syserr.errcondition.overview]](syserr.errcondition.overview)

[1](#errcondition.overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1238)

The class error_condition describes an object used to hold values identifying
error conditions[.](#errcondition.overview-1.sentence-1)

[*Note [1](#errcondition.overview-note-1)*:

error_condition values are portable abstractions,
while error_code values ([[syserr.errcode]](#errcode "19.5.4 Class error_­code")) are implementation specific[.](#errcondition.overview-1.sentence-2)

â *end note*]

[ð](#lib:error_condition_)

namespace std {class error_condition {public:// [[syserr.errcondition.constructors]](#errcondition.constructors "19.5.5.2 Constructors"), constructors error_condition() noexcept;
 error_condition(int val, const error_category& cat) noexcept; template<class ErrorConditionEnum> error_condition(ErrorConditionEnum e) noexcept; // [[syserr.errcondition.modifiers]](#errcondition.modifiers "19.5.5.3 Modifiers"), modifiersvoid assign(int val, const error_category& cat) noexcept; template<class ErrorConditionEnum> error_condition& operator=(ErrorConditionEnum e) noexcept; void clear() noexcept; // [[syserr.errcondition.observers]](#errcondition.observers "19.5.5.4 Observers"), observersint value() const noexcept; const error_category& category() const noexcept;
 string message() const; explicit operator bool() const noexcept; private:int *val_*; // *exposition only*const error_category* *cat_*; // *exposition only*};}

#### [19.5.5.2](#errcondition.constructors) Constructors [[syserr.errcondition.constructors]](syserr.errcondition.constructors)

[ð](#lib:error_condition,constructor)

`error_condition() noexcept;
`

[1](#errcondition.constructors-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1284)

*Effects*: Initializes *val_* with 0 and *cat_* with &generic_category()[.](#errcondition.constructors-1.sentence-1)

[ð](#lib:error_condition,constructor_)

`error_condition(int val, const error_category& cat) noexcept;
`

[2](#errcondition.constructors-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1296)

*Effects*: Initializes *val_* with val and *cat_* with &cat[.](#errcondition.constructors-2.sentence-1)

[ð](#lib:error_condition,constructor__)

`template<class ErrorConditionEnum>
  error_condition(ErrorConditionEnum e) noexcept;
`

[3](#errcondition.constructors-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1309)

*Constraints*: is_error_condition_enum_v<ErrorConditionEnum> is true[.](#errcondition.constructors-3.sentence-1)

[4](#errcondition.constructors-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1313)

*Effects*: Equivalent to:error_condition ec = make_error_condition(e);
assign(ec.value(), ec.category());

#### [19.5.5.3](#errcondition.modifiers) Modifiers [[syserr.errcondition.modifiers]](syserr.errcondition.modifiers)

[ð](#lib:assign,error_condition)

`void assign(int val, const error_category& cat) noexcept;
`

[1](#errcondition.modifiers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1331)

*Postconditions*: *val_* == val and *cat_* == &cat[.](#errcondition.modifiers-1.sentence-1)

[ð](#lib:operator=,error_condition)

`template<class ErrorConditionEnum>
  error_condition& operator=(ErrorConditionEnum e) noexcept;
`

[2](#errcondition.modifiers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1343)

*Constraints*: is_error_condition_enum_v<ErrorConditionEnum> is true[.](#errcondition.modifiers-2.sentence-1)

[3](#errcondition.modifiers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1347)

*Effects*: Equivalent to:error_condition ec = make_error_condition(e);
assign(ec.value(), ec.category());

[4](#errcondition.modifiers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1355)

*Returns*: *this[.](#errcondition.modifiers-4.sentence-1)

[ð](#lib:clear,error_condition)

`void clear() noexcept;
`

[5](#errcondition.modifiers-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1366)

*Postconditions*: value() == 0 and category() == generic_category()[.](#errcondition.modifiers-5.sentence-1)

#### [19.5.5.4](#errcondition.observers) Observers [[syserr.errcondition.observers]](syserr.errcondition.observers)

[ð](#lib:value,error_condition)

`int value() const noexcept;
`

[1](#errcondition.observers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1379)

*Returns*: *val_*[.](#errcondition.observers-1.sentence-1)

[ð](#lib:category,error_condition)

`const error_category& category() const noexcept;
`

[2](#errcondition.observers-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1390)

*Returns*: **cat_*[.](#errcondition.observers-2.sentence-1)

[ð](#lib:message,error_condition)

`string message() const;
`

[3](#errcondition.observers-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1401)

*Returns*: category().message(value())[.](#errcondition.observers-3.sentence-1)

[ð](#lib:operator_bool,error_condition)

`explicit operator bool() const noexcept;
`

[4](#errcondition.observers-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1412)

*Returns*: value() != 0[.](#errcondition.observers-4.sentence-1)

#### [19.5.5.5](#errcondition.nonmembers) Non-member functions [[syserr.errcondition.nonmembers]](syserr.errcondition.nonmembers)

[ð](#lib:make_error_condition,errc)

`error_condition make_error_condition(errc e) noexcept;
`

[1](#errcondition.nonmembers-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1425)

*Returns*: error_condition(static_cast<int>(e), generic_category())[.](#errcondition.nonmembers-1.sentence-1)

### [19.5.6](#compare) Comparison operator functions [[syserr.compare]](syserr.compare)

[ð](#lib:operator==,error_code)

`bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
`

[1](#compare-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1438)

*Returns*: lhs.category() == rhs.category() && lhs.value() == rhs.value()

[ð](#lib:operator==,error_condition)

`bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
`

[2](#compare-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1452)

*Returns*: lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs, rhs.value())

[ð](#lib:operator==,error_condition_)

`bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
`

[3](#compare-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1465)

*Returns*: lhs.category() == rhs.category() && lhs.value() == rhs.value()

[ð](#lib:operator%3c=%3e,error_code)

`strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept;
`

[4](#compare-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1478)

*Effects*: Equivalent to:if (auto c = lhs.category() <=> rhs.category(); c != 0) return c;return lhs.value() <=> rhs.value();

[ð](#lib:operator%3c=%3e,error_condition)

`strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept;
`

[5](#compare-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1493)

*Returns*: if (auto c = lhs.category() <=> rhs.category(); c != 0) return c;return lhs.value() <=> rhs.value();

### [19.5.7](#hash) System error hash support [[syserr.hash]](syserr.hash)

[ð](#lib:hash,error_code)

`template<> struct hash<error_code>;
template<> struct hash<error_condition>;
`

[1](#hash-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1510)

The specializations are enabled ([[unord.hash]](unord.hash "22.10.19 Class template hash"))[.](#hash-1.sentence-1)

### [19.5.8](#syserr) Class system_error [[syserr.syserr]](syserr.syserr)

#### [19.5.8.1](#syserr.overview) Overview [[syserr.syserr.overview]](syserr.syserr.overview)

[1](#syserr.overview-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1518)

The class system_error describes an exception object used to
report error conditions that have an associated error code[.](#syserr.overview-1.sentence-1)

Such error
conditions typically originate from the operating system or other low-level
application program interfaces[.](#syserr.overview-1.sentence-2)

[2](#syserr.overview-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1524)

[*Note [1](#syserr.overview-note-1)*:

If an error represents an out-of-memory condition, implementations are
encouraged to throw an exception object of type [bad_alloc](bad.alloc "17.6.4.1 Class bad_­alloc [bad.alloc]") rather
than system_error[.](#syserr.overview-2.sentence-1)

â *end note*]

[ð](#lib:system_error_)

namespace std {class system_error : public runtime_error {public: system_error(error_code ec, const string& what_arg);
 system_error(error_code ec, const char* what_arg);
 system_error(error_code ec);
 system_error(int ev, const error_category& ecat, const string& what_arg);
 system_error(int ev, const error_category& ecat, const char* what_arg);
 system_error(int ev, const error_category& ecat); const error_code& code() const noexcept; const char* what() const noexcept override; };}

#### [19.5.8.2](#syserr.members) Members [[syserr.syserr.members]](syserr.syserr.members)

[ð](#lib:system_error,constructor)

`system_error(error_code ec, const string& what_arg);
`

[1](#syserr.members-1)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1555)

*Postconditions*: code() == ec and  
string_view(what()).find(what_arg.c_str()) != string_view​::​npos[.](#syserr.members-1.sentence-1)

[ð](#lib:system_error,constructor_)

`system_error(error_code ec, const char* what_arg);
`

[2](#syserr.members-2)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1567)

*Postconditions*: code() == ec andstring_view(what()).find(what_arg) != string_view​::​npos[.](#syserr.members-2.sentence-1)

[ð](#lib:system_error,constructor__)

`system_error(error_code ec);
`

[3](#syserr.members-3)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1579)

*Postconditions*: code() == ec[.](#syserr.members-3.sentence-1)

[ð](#lib:system_error,constructor___)

`system_error(int ev, const error_category& ecat, const string& what_arg);
`

[4](#syserr.members-4)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1590)

*Postconditions*: code() == error_code(ev, ecat) and  
string_view(what()).find(what_arg.c_str()) != string_view​::​npos[.](#syserr.members-4.sentence-1)

[ð](#lib:system_error,constructor____)

`system_error(int ev, const error_category& ecat, const char* what_arg);
`

[5](#syserr.members-5)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1602)

*Postconditions*: code() == error_code(ev, ecat) and  
string_view(what()).find(what_arg) != string_view​::​npos[.](#syserr.members-5.sentence-1)

[ð](#lib:system_error,constructor_____)

`system_error(int ev, const error_category& ecat);
`

[6](#syserr.members-6)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1614)

*Postconditions*: code() == error_code(ev, ecat)[.](#syserr.members-6.sentence-1)

[ð](#lib:code,system_error)

`const error_code& code() const noexcept;
`

[7](#syserr.members-7)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1625)

*Returns*: ec or error_code(ev, ecat), from the constructor,
as appropriate[.](#syserr.members-7.sentence-1)

[ð](#lib:what,system_error)

`const char* what() const noexcept override;
`

[8](#syserr.members-8)

[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1637)

*Returns*: An ntbs incorporating the arguments supplied in the constructor[.](#syserr.members-8.sentence-1)

[*Note [1](#syserr.members-note-1)*:

The returned ntbs might be the contents of what_arg + ": " + code.message()[.](#syserr.members-8.sentence-2)

â *end note*]
