206 lines
7.0 KiB
Markdown
206 lines
7.0 KiB
Markdown
[syserr.errcode]
|
||
|
||
# 19 Diagnostics library [[diagnostics]](./#diagnostics)
|
||
|
||
## 19.5 System error support [[syserr]](syserr#errcode)
|
||
|
||
### 19.5.4 Class error_code [syserr.errcode]
|
||
|
||
#### [19.5.4.1](#overview) Overview [[syserr.errcode.overview]](syserr.errcode.overview)
|
||
|
||
[1](#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[.](#overview-1.sentence-1)
|
||
|
||
[*Note [1](#overview-note-1)*:
|
||
|
||
Class error_code is an
|
||
adjunct to error reporting by exception[.](#overview-1.sentence-2)
|
||
|
||
â *end note*]
|
||
|
||
[ð](#lib:error_code)
|
||
|
||
namespace std {class error_code {public:// [[syserr.errcode.constructors]](#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]](#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]](#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]](#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](#constructors) Constructors [[syserr.errcode.constructors]](syserr.errcode.constructors)
|
||
|
||
[ð](#lib:error_code,constructor)
|
||
|
||
`error_code() noexcept;
|
||
`
|
||
|
||
[1](#constructors-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1064)
|
||
|
||
*Effects*: Initializes *val_* with 0 and *cat_* with &system_category()[.](#constructors-1.sentence-1)
|
||
|
||
[ð](#lib:error_code,constructor_)
|
||
|
||
`error_code(int val, const error_category& cat) noexcept;
|
||
`
|
||
|
||
[2](#constructors-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1076)
|
||
|
||
*Effects*: Initializes *val_* with val and *cat_* with &cat[.](#constructors-2.sentence-1)
|
||
|
||
[ð](#lib:error_code,constructor__)
|
||
|
||
`template<class ErrorCodeEnum>
|
||
error_code(ErrorCodeEnum e) noexcept;
|
||
`
|
||
|
||
[3](#constructors-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1089)
|
||
|
||
*Constraints*: [is_error_code_enum_v](system.error.syn#lib:is_error_code_enum_v "19.5.2 Header <system_error> synopsis [system.error.syn]")<ErrorCodeEnum> is true[.](#constructors-3.sentence-1)
|
||
|
||
[4](#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](#modifiers) Modifiers [[syserr.errcode.modifiers]](syserr.errcode.modifiers)
|
||
|
||
[ð](#lib:assign,error_code)
|
||
|
||
`void assign(int val, const error_category& cat) noexcept;
|
||
`
|
||
|
||
[1](#modifiers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1110)
|
||
|
||
*Postconditions*: *val_* == val and *cat_* == &cat[.](#modifiers-1.sentence-1)
|
||
|
||
[ð](#lib:operator=,error_code)
|
||
|
||
`template<class ErrorCodeEnum>
|
||
error_code& operator=(ErrorCodeEnum e) noexcept;
|
||
`
|
||
|
||
[2](#modifiers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1122)
|
||
|
||
*Constraints*: [is_error_code_enum_v](system.error.syn#lib:is_error_code_enum_v "19.5.2 Header <system_error> synopsis [system.error.syn]")<ErrorCodeEnum> is true[.](#modifiers-2.sentence-1)
|
||
|
||
[3](#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](#modifiers-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1134)
|
||
|
||
*Returns*: *this[.](#modifiers-4.sentence-1)
|
||
|
||
[ð](#lib:clear,error_code)
|
||
|
||
`void clear() noexcept;
|
||
`
|
||
|
||
[5](#modifiers-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1145)
|
||
|
||
*Postconditions*: value() == 0 and category() == system_category()[.](#modifiers-5.sentence-1)
|
||
|
||
#### [19.5.4.4](#observers) Observers [[syserr.errcode.observers]](syserr.errcode.observers)
|
||
|
||
[ð](#lib:value,error_code)
|
||
|
||
`int value() const noexcept;
|
||
`
|
||
|
||
[1](#observers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1159)
|
||
|
||
*Returns*: *val_*[.](#observers-1.sentence-1)
|
||
|
||
[ð](#lib:category,error_code)
|
||
|
||
`const error_category& category() const noexcept;
|
||
`
|
||
|
||
[2](#observers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1170)
|
||
|
||
*Returns*: **cat_*[.](#observers-2.sentence-1)
|
||
|
||
[ð](#lib:default_error_condition,error_code)
|
||
|
||
`error_condition default_error_condition() const noexcept;
|
||
`
|
||
|
||
[3](#observers-3)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1181)
|
||
|
||
*Returns*: category().default_error_condition(value())[.](#observers-3.sentence-1)
|
||
|
||
[ð](#lib:message,error_code)
|
||
|
||
`string message() const;
|
||
`
|
||
|
||
[4](#observers-4)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1192)
|
||
|
||
*Returns*: category().message(value())[.](#observers-4.sentence-1)
|
||
|
||
[ð](#lib:operator_bool,error_code)
|
||
|
||
`explicit operator bool() const noexcept;
|
||
`
|
||
|
||
[5](#observers-5)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1203)
|
||
|
||
*Returns*: value() != 0[.](#observers-5.sentence-1)
|
||
|
||
#### [19.5.4.5](#nonmembers) Non-member functions [[syserr.errcode.nonmembers]](syserr.errcode.nonmembers)
|
||
|
||
[ð](#lib:make_error_code,errc)
|
||
|
||
`error_code make_error_code(errc e) noexcept;
|
||
`
|
||
|
||
[1](#nonmembers-1)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1216)
|
||
|
||
*Returns*: error_code(static_cast<int>(e), generic_category())[.](#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](#nonmembers-2)
|
||
|
||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/diagnostics.tex#L1228)
|
||
|
||
*Effects*: Equivalent to: return os << ec.category().name() << ':' << ec.value();
|