[syserr.errcat] # 19 Diagnostics library [[diagnostics]](./#diagnostics) ## 19.5 System error support [[syserr]](syserr#errcat) ### 19.5.3 Class error_category [syserr.errcat] #### [19.5.3.1](#overview) Overview [[syserr.errcat.overview]](syserr.errcat.overview) [1](#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[.](#overview-1.sentence-1) Classes may be derived from error_category to support categories of errors in addition to those defined in this document[.](#overview-1.sentence-2) Such classes shall behave as specified in subclause [syserr.errcat][.](#overview-1.sentence-3) [*Note [1](#overview-note-1)*: error_category objects are passed by reference, and two such objects are equal if they have the same address[.](#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[.](#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](#virtuals) Virtual members [[syserr.errcat.virtuals]](syserr.errcat.virtuals) [🔗](#lib:name,error_category) `virtual const char* name() const noexcept = 0; ` [1](#virtuals-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L832) *Returns*: A string naming the error category[.](#virtuals-1.sentence-1) [🔗](#lib:default_error_condition,error_category) `virtual error_condition default_error_condition(int ev) const noexcept; ` [2](#virtuals-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L843) *Returns*: error_condition(ev, *this)[.](#virtuals-2.sentence-1) [🔗](#lib:equivalent,error_category) `virtual bool equivalent(int code, const error_condition& condition) const noexcept; ` [3](#virtuals-3) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L854) *Returns*: default_error_condition(code) == condition[.](#virtuals-3.sentence-1) [🔗](#lib:equivalent,error_category_) `virtual bool equivalent(const error_code& code, int condition) const noexcept; ` [4](#virtuals-4) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L865) *Returns*: *this == code.category() && code.value() == condition[.](#virtuals-4.sentence-1) [🔗](#lib:message,error_category) `virtual string message(int ev) const = 0; ` [5](#virtuals-5) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L876) *Returns*: A string that describes the error condition denoted by ev[.](#virtuals-5.sentence-1) #### [19.5.3.3](#nonvirtuals) Non-virtual members [[syserr.errcat.nonvirtuals]](syserr.errcat.nonvirtuals) [🔗](#lib:operator==,error_category) `bool operator==(const error_category& rhs) const noexcept; ` [1](#nonvirtuals-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L889) *Returns*: this == &rhs[.](#nonvirtuals-1.sentence-1) [🔗](#lib:operator%3c=%3e,error_category) `strong_ordering operator<=>(const error_category& rhs) const noexcept; ` [2](#nonvirtuals-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L900) *Returns*: compare_three_way()(this, &rhs)[.](#nonvirtuals-2.sentence-1) [*Note [1](#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[.](#nonvirtuals-2.sentence-2) — *end note*] #### [19.5.3.4](#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](#derived-1) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L917) *Returns*: A string naming the error category[.](#derived-1.sentence-1) [🔗](#lib:default_error_condition,error_category_) `virtual error_condition default_error_condition(int ev) const noexcept; ` [2](#derived-2) [#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L928) *Returns*: An object of type error_condition that corresponds to ev[.](#derived-2.sentence-1) [🔗](#lib:equivalent,error_category__) `virtual bool equivalent(int code, const error_condition& condition) const noexcept; ` [3](#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[.](#derived-3.sentence-1) [🔗](#lib:equivalent,error_category___) `virtual bool equivalent(const error_code& code, int condition) const noexcept; ` [4](#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[.](#derived-4.sentence-1) #### [19.5.3.5](#objects) Error category objects [[syserr.errcat.objects]](syserr.errcat.objects) [🔗](#lib:generic_category_) `const error_category& generic_category() noexcept; ` [1](#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[.](#objects-1.sentence-1) All calls to this function shall return references to the same object[.](#objects-1.sentence-2) [2](#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[.](#objects-2.sentence-1) The object's name virtual function shall return a pointer to the string "generic"[.](#objects-2.sentence-2) [🔗](#lib:system_category_) `const error_category& system_category() noexcept; ` [3](#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[.](#objects-3.sentence-1) All calls to this function shall return references to the same object[.](#objects-3.sentence-2) [4](#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[.](#objects-4.sentence-1) The object's name virtual function shall return a pointer to the string "system"[.](#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())[.](#objects-4.sentence-4) Otherwise, if ev corresponds to a POSIX errno value pxv, the function returns error_condition(pxv, generic_category())[.](#objects-4.sentence-5) Otherwise, the function returns error_condition(ev, system_category())[.](#objects-4.sentence-6) What constitutes correspondence for any given operating system is unspecified[.](#objects-4.sentence-7) [*Note [1](#objects-note-1)*: The number of potential system error codes is large and unbounded, and some might not correspond to any POSIX errno value[.](#objects-4.sentence-8) Thus implementations are given latitude in determining correspondence[.](#objects-4.sentence-9) — *end note*]