- tmp/tmpm92_nckj/{from.md → to.md} +134 -230
tmp/tmpm92_nckj/{from.md → to.md}
RENAMED
|
@@ -5,14 +5,14 @@
|
|
| 5 |
This Clause describes components that C++ programs may use to detect and
|
| 6 |
report error conditions.
|
| 7 |
|
| 8 |
The following subclauses describe components for reporting several kinds
|
| 9 |
of exceptional conditions, documenting program assertions, and a global
|
| 10 |
-
variable for error number codes, as summarized in
|
| 11 |
-
[[
|
| 12 |
|
| 13 |
-
**Table: Diagnostics library summary** <a id="
|
| 14 |
|
| 15 |
| Subclause | | Header |
|
| 16 |
| ------------------ | -------------------- | ---------------- |
|
| 17 |
| [[std.exceptions]] | Exception classes | `<stdexcept>` |
|
| 18 |
| [[assertions]] | Assertions | `<cassert>` |
|
|
@@ -21,12 +21,12 @@ variable for error number codes, as summarized in Table
|
|
| 21 |
|
| 22 |
|
| 23 |
## Exception classes <a id="std.exceptions">[[std.exceptions]]</a>
|
| 24 |
|
| 25 |
The C++ standard library provides classes to be used to report certain
|
| 26 |
-
errors
|
| 27 |
-
|
| 28 |
categories: *logic* errors and *runtime* errors.
|
| 29 |
|
| 30 |
The distinguishing characteristic of logic errors is that they are due
|
| 31 |
to errors in the internal logic of the program. In theory, they are
|
| 32 |
preventable.
|
|
@@ -71,21 +71,17 @@ as violations of logical preconditions or class invariants.
|
|
| 71 |
|
| 72 |
``` cpp
|
| 73 |
logic_error(const string& what_arg);
|
| 74 |
```
|
| 75 |
|
| 76 |
-
*
|
| 77 |
-
|
| 78 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
logic_error(const char* what_arg);
|
| 82 |
```
|
| 83 |
|
| 84 |
-
*
|
| 85 |
-
|
| 86 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 87 |
|
| 88 |
### Class `domain_error` <a id="domain.error">[[domain.error]]</a>
|
| 89 |
|
| 90 |
``` cpp
|
| 91 |
namespace std {
|
|
@@ -102,21 +98,17 @@ exceptions by the implementation to report domain errors.
|
|
| 102 |
|
| 103 |
``` cpp
|
| 104 |
domain_error(const string& what_arg);
|
| 105 |
```
|
| 106 |
|
| 107 |
-
*
|
| 108 |
-
|
| 109 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 110 |
|
| 111 |
``` cpp
|
| 112 |
domain_error(const char* what_arg);
|
| 113 |
```
|
| 114 |
|
| 115 |
-
*
|
| 116 |
-
|
| 117 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 118 |
|
| 119 |
### Class `invalid_argument` <a id="invalid.argument">[[invalid.argument]]</a>
|
| 120 |
|
| 121 |
``` cpp
|
| 122 |
namespace std {
|
|
@@ -133,21 +125,17 @@ exceptions to report an invalid argument.
|
|
| 133 |
|
| 134 |
``` cpp
|
| 135 |
invalid_argument(const string& what_arg);
|
| 136 |
```
|
| 137 |
|
| 138 |
-
*
|
| 139 |
-
|
| 140 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 141 |
|
| 142 |
``` cpp
|
| 143 |
invalid_argument(const char* what_arg);
|
| 144 |
```
|
| 145 |
|
| 146 |
-
*
|
| 147 |
-
|
| 148 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 149 |
|
| 150 |
### Class `length_error` <a id="length.error">[[length.error]]</a>
|
| 151 |
|
| 152 |
``` cpp
|
| 153 |
namespace std {
|
|
@@ -165,21 +153,17 @@ exceeds its maximum allowable size.
|
|
| 165 |
|
| 166 |
``` cpp
|
| 167 |
length_error(const string& what_arg);
|
| 168 |
```
|
| 169 |
|
| 170 |
-
*
|
| 171 |
-
|
| 172 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 173 |
|
| 174 |
``` cpp
|
| 175 |
length_error(const char* what_arg);
|
| 176 |
```
|
| 177 |
|
| 178 |
-
*
|
| 179 |
-
|
| 180 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 181 |
|
| 182 |
### Class `out_of_range` <a id="out.of.range">[[out.of.range]]</a>
|
| 183 |
|
| 184 |
``` cpp
|
| 185 |
namespace std {
|
|
@@ -196,21 +180,17 @@ exceptions to report an argument value not in its expected range.
|
|
| 196 |
|
| 197 |
``` cpp
|
| 198 |
out_of_range(const string& what_arg);
|
| 199 |
```
|
| 200 |
|
| 201 |
-
*
|
| 202 |
-
|
| 203 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 204 |
|
| 205 |
``` cpp
|
| 206 |
out_of_range(const char* what_arg);
|
| 207 |
```
|
| 208 |
|
| 209 |
-
*
|
| 210 |
-
|
| 211 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 212 |
|
| 213 |
### Class `runtime_error` <a id="runtime.error">[[runtime.error]]</a>
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
namespace std {
|
|
@@ -228,21 +208,17 @@ executes.
|
|
| 228 |
|
| 229 |
``` cpp
|
| 230 |
runtime_error(const string& what_arg);
|
| 231 |
```
|
| 232 |
|
| 233 |
-
*
|
| 234 |
-
|
| 235 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 236 |
|
| 237 |
``` cpp
|
| 238 |
runtime_error(const char* what_arg);
|
| 239 |
```
|
| 240 |
|
| 241 |
-
*
|
| 242 |
-
|
| 243 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 244 |
|
| 245 |
### Class `range_error` <a id="range.error">[[range.error]]</a>
|
| 246 |
|
| 247 |
``` cpp
|
| 248 |
namespace std {
|
|
@@ -259,21 +235,17 @@ to report range errors in internal computations.
|
|
| 259 |
|
| 260 |
``` cpp
|
| 261 |
range_error(const string& what_arg);
|
| 262 |
```
|
| 263 |
|
| 264 |
-
*
|
| 265 |
-
|
| 266 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 267 |
|
| 268 |
``` cpp
|
| 269 |
range_error(const char* what_arg);
|
| 270 |
```
|
| 271 |
|
| 272 |
-
*
|
| 273 |
-
|
| 274 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 275 |
|
| 276 |
### Class `overflow_error` <a id="overflow.error">[[overflow.error]]</a>
|
| 277 |
|
| 278 |
``` cpp
|
| 279 |
namespace std {
|
|
@@ -290,21 +262,17 @@ exceptions to report an arithmetic overflow error.
|
|
| 290 |
|
| 291 |
``` cpp
|
| 292 |
overflow_error(const string& what_arg);
|
| 293 |
```
|
| 294 |
|
| 295 |
-
*
|
| 296 |
-
|
| 297 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
overflow_error(const char* what_arg);
|
| 301 |
```
|
| 302 |
|
| 303 |
-
*
|
| 304 |
-
|
| 305 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 306 |
|
| 307 |
### Class `underflow_error` <a id="underflow.error">[[underflow.error]]</a>
|
| 308 |
|
| 309 |
``` cpp
|
| 310 |
namespace std {
|
|
@@ -321,21 +289,17 @@ exceptions to report an arithmetic underflow error.
|
|
| 321 |
|
| 322 |
``` cpp
|
| 323 |
underflow_error(const string& what_arg);
|
| 324 |
```
|
| 325 |
|
| 326 |
-
*
|
| 327 |
-
|
| 328 |
-
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 329 |
|
| 330 |
``` cpp
|
| 331 |
underflow_error(const char* what_arg);
|
| 332 |
```
|
| 333 |
|
| 334 |
-
*
|
| 335 |
-
|
| 336 |
-
*Postconditions:* `strcmp(what(), what_arg) == 0`.
|
| 337 |
|
| 338 |
## Assertions <a id="assertions">[[assertions]]</a>
|
| 339 |
|
| 340 |
The header `<cassert>` provides a macro for documenting C++ program
|
| 341 |
assertions and a mechanism for disabling the assertion checks.
|
|
@@ -347,20 +311,20 @@ assertions and a mechanism for disabling the assertion checks.
|
|
| 347 |
```
|
| 348 |
|
| 349 |
The contents are the same as the C standard library header `<assert.h>`,
|
| 350 |
except that a macro named `static_assert` is not defined.
|
| 351 |
|
| 352 |
-
ISO C
|
| 353 |
|
| 354 |
### The `assert` macro <a id="assertions.assert">[[assertions.assert]]</a>
|
| 355 |
|
| 356 |
-
An expression `assert(E)` is a constant subexpression
|
| 357 |
-
[[defns.const.subexpr]]
|
| 358 |
|
| 359 |
- `NDEBUG` is defined at the point where `assert` is last defined or
|
| 360 |
redefined, or
|
| 361 |
-
- `E` contextually converted to `bool`
|
| 362 |
subexpression that evaluates to the value `true`.
|
| 363 |
|
| 364 |
## Error numbers <a id="errno">[[errno]]</a>
|
| 365 |
|
| 366 |
The contents of the header `<cerrno>` are the same as the POSIX header
|
|
@@ -457,25 +421,27 @@ A separate `errno` value shall be provided for each thread.
|
|
| 457 |
```
|
| 458 |
|
| 459 |
The meaning of the macros in this header is defined by the POSIX
|
| 460 |
standard.
|
| 461 |
|
| 462 |
-
ISO C
|
| 463 |
|
| 464 |
## System error support <a id="syserr">[[syserr]]</a>
|
| 465 |
|
| 466 |
-
This subclause describes components that the standard library and
|
| 467 |
-
|
| 468 |
operating system or other low-level application program interfaces.
|
| 469 |
|
| 470 |
Components described in this subclause shall not change the value of
|
| 471 |
-
`errno`
|
| 472 |
provided by other libraries unchanged.
|
| 473 |
|
| 474 |
-
### Header `<system_error>` synopsis <a id="
|
| 475 |
|
| 476 |
``` cpp
|
|
|
|
|
|
|
| 477 |
namespace std {
|
| 478 |
class error_category;
|
| 479 |
const error_category& generic_category() noexcept;
|
| 480 |
const error_category& system_category() noexcept;
|
| 481 |
|
|
@@ -581,53 +547,48 @@ namespace std {
|
|
| 581 |
|
| 582 |
// [syserr.errcondition.nonmembers], non-member functions
|
| 583 |
error_condition make_error_condition(errc e) noexcept;
|
| 584 |
|
| 585 |
// [syserr.compare], comparison functions
|
| 586 |
-
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 587 |
-
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 588 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 589 |
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 590 |
-
bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 591 |
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 595 |
-
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 596 |
|
| 597 |
// [syserr.hash], hash support
|
| 598 |
template<class T> struct hash;
|
| 599 |
template<> struct hash<error_code>;
|
| 600 |
template<> struct hash<error_condition>;
|
| 601 |
|
| 602 |
// [syserr], system error support
|
| 603 |
-
template
|
| 604 |
-
= is_error_code_enum<T>::value;
|
| 605 |
-
template
|
| 606 |
-
= is_error_condition_enum<T>::value;
|
| 607 |
}
|
| 608 |
```
|
| 609 |
|
| 610 |
The value of each `enum errc` constant shall be the same as the value of
|
| 611 |
the `<cerrno>` macro shown in the above synopsis. Whether or not the
|
| 612 |
`<system_error>` implementation exposes the `<cerrno>` macros is
|
| 613 |
unspecified.
|
| 614 |
|
| 615 |
The `is_error_code_enum` and `is_error_condition_enum` may be
|
| 616 |
-
specialized for
|
| 617 |
eligible for `class error_code` and `class error_condition` automatic
|
| 618 |
conversions, respectively.
|
| 619 |
|
| 620 |
### Class `error_category` <a id="syserr.errcat">[[syserr.errcat]]</a>
|
| 621 |
|
| 622 |
-
####
|
| 623 |
|
| 624 |
The class `error_category` serves as a base class for types used to
|
| 625 |
identify the source and encoding of a particular category of error code.
|
| 626 |
Classes may be derived from `error_category` to support categories of
|
| 627 |
-
errors in addition to those defined in this
|
| 628 |
-
|
| 629 |
|
| 630 |
[*Note 1*: `error_category` objects are passed by reference, and two
|
| 631 |
such objects are equal if they have the same address. This means that
|
| 632 |
applications using custom `error_category` types should create a single
|
| 633 |
object of each such type. — *end note*]
|
|
@@ -645,26 +606,19 @@ namespace std {
|
|
| 645 |
virtual bool equivalent(int code, const error_condition& condition) const noexcept;
|
| 646 |
virtual bool equivalent(const error_code& code, int condition) const noexcept;
|
| 647 |
virtual string message(int ev) const = 0;
|
| 648 |
|
| 649 |
bool operator==(const error_category& rhs) const noexcept;
|
| 650 |
-
|
| 651 |
-
bool operator<(const error_category& rhs) const noexcept;
|
| 652 |
};
|
| 653 |
|
| 654 |
const error_category& generic_category() noexcept;
|
| 655 |
const error_category& system_category() noexcept;
|
| 656 |
}
|
| 657 |
```
|
| 658 |
|
| 659 |
-
####
|
| 660 |
-
|
| 661 |
-
``` cpp
|
| 662 |
-
virtual ~error_category();
|
| 663 |
-
```
|
| 664 |
-
|
| 665 |
-
*Effects:* Destroys an object of class `error_category`.
|
| 666 |
|
| 667 |
``` cpp
|
| 668 |
virtual const char* name() const noexcept = 0;
|
| 669 |
```
|
| 670 |
|
|
@@ -692,40 +646,28 @@ virtual bool equivalent(const error_code& code, int condition) const noexcept;
|
|
| 692 |
virtual string message(int ev) const = 0;
|
| 693 |
```
|
| 694 |
|
| 695 |
*Returns:* A string that describes the error condition denoted by `ev`.
|
| 696 |
|
| 697 |
-
####
|
| 698 |
-
|
| 699 |
-
``` cpp
|
| 700 |
-
constexpr error_category() noexcept;
|
| 701 |
-
```
|
| 702 |
-
|
| 703 |
-
*Effects:* Constructs an object of class `error_category`.
|
| 704 |
|
| 705 |
``` cpp
|
| 706 |
bool operator==(const error_category& rhs) const noexcept;
|
| 707 |
```
|
| 708 |
|
| 709 |
*Returns:* `this == &rhs`.
|
| 710 |
|
| 711 |
``` cpp
|
| 712 |
-
|
| 713 |
```
|
| 714 |
|
| 715 |
-
*Returns:* `
|
| 716 |
|
| 717 |
-
``
|
| 718 |
-
|
| 719 |
-
```
|
| 720 |
-
|
| 721 |
-
*Returns:* `less<const error_category*>()(this, &rhs)`.
|
| 722 |
-
|
| 723 |
-
[*Note 1*: `less` ([[comparisons]]) provides a total ordering for
|
| 724 |
-
pointers. — *end note*]
|
| 725 |
|
| 726 |
-
#### Program
|
| 727 |
|
| 728 |
``` cpp
|
| 729 |
virtual const char* name() const noexcept = 0;
|
| 730 |
```
|
| 731 |
|
|
@@ -790,11 +732,11 @@ unbounded, and some may not correspond to any POSIX `errno` value. Thus
|
|
| 790 |
implementations are given latitude in determining
|
| 791 |
correspondence. — *end note*]
|
| 792 |
|
| 793 |
### Class `error_code` <a id="syserr.errcode">[[syserr.errcode]]</a>
|
| 794 |
|
| 795 |
-
####
|
| 796 |
|
| 797 |
The class `error_code` describes an object used to hold error code
|
| 798 |
values, such as those originating from the operating system or other
|
| 799 |
low-level application program interfaces.
|
| 800 |
|
|
@@ -836,71 +778,59 @@ namespace std {
|
|
| 836 |
basic_ostream<charT, traits>&
|
| 837 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 838 |
}
|
| 839 |
```
|
| 840 |
|
| 841 |
-
####
|
| 842 |
|
| 843 |
``` cpp
|
| 844 |
error_code() noexcept;
|
| 845 |
```
|
| 846 |
|
| 847 |
-
*
|
| 848 |
-
|
| 849 |
-
*Postconditions:* `val_ == 0` and `cat_ == &system_category()`.
|
| 850 |
|
| 851 |
``` cpp
|
| 852 |
error_code(int val, const error_category& cat) noexcept;
|
| 853 |
```
|
| 854 |
|
| 855 |
-
*
|
| 856 |
-
|
| 857 |
-
*Postconditions:* `val_ == val` and `cat_ == &cat`.
|
| 858 |
|
| 859 |
``` cpp
|
| 860 |
template<class ErrorCodeEnum>
|
| 861 |
error_code(ErrorCodeEnum e) noexcept;
|
| 862 |
```
|
| 863 |
|
| 864 |
-
*
|
| 865 |
|
| 866 |
-
*
|
| 867 |
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
This constructor shall not participate in overload resolution unless
|
| 871 |
-
`is_error_code_enum_v<ErrorCodeEnum>` is `true`.
|
| 872 |
-
|
| 873 |
-
#### Class `error_code` modifiers <a id="syserr.errcode.modifiers">[[syserr.errcode.modifiers]]</a>
|
| 874 |
|
| 875 |
``` cpp
|
| 876 |
void assign(int val, const error_category& cat) noexcept;
|
| 877 |
```
|
| 878 |
|
| 879 |
-
*
|
| 880 |
|
| 881 |
``` cpp
|
| 882 |
template<class ErrorCodeEnum>
|
| 883 |
error_code& operator=(ErrorCodeEnum e) noexcept;
|
| 884 |
```
|
| 885 |
|
| 886 |
-
*
|
|
|
|
|
|
|
| 887 |
|
| 888 |
*Returns:* `*this`.
|
| 889 |
|
| 890 |
-
*Remarks:*
|
| 891 |
-
|
| 892 |
-
This operator shall not participate in overload resolution unless
|
| 893 |
-
`is_error_code_enum_v<ErrorCodeEnum>` is `true`.
|
| 894 |
-
|
| 895 |
``` cpp
|
| 896 |
void clear() noexcept;
|
| 897 |
```
|
| 898 |
|
| 899 |
-
*
|
| 900 |
|
| 901 |
-
####
|
| 902 |
|
| 903 |
``` cpp
|
| 904 |
int value() const noexcept;
|
| 905 |
```
|
| 906 |
|
|
@@ -928,35 +858,35 @@ string message() const;
|
|
| 928 |
explicit operator bool() const noexcept;
|
| 929 |
```
|
| 930 |
|
| 931 |
*Returns:* `value() != 0`.
|
| 932 |
|
| 933 |
-
####
|
| 934 |
|
| 935 |
``` cpp
|
| 936 |
error_code make_error_code(errc e) noexcept;
|
| 937 |
```
|
| 938 |
|
| 939 |
*Returns:* `error_code(static_cast<int>(e), generic_category())`.
|
| 940 |
|
| 941 |
``` cpp
|
| 942 |
template<class charT, class traits>
|
| 943 |
-
basic_ostream<charT, traits>&
|
| 944 |
-
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 945 |
```
|
| 946 |
|
| 947 |
-
*Effects:*
|
|
|
|
| 948 |
|
| 949 |
### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
|
| 950 |
|
| 951 |
-
####
|
| 952 |
|
| 953 |
The class `error_condition` describes an object used to hold values
|
| 954 |
identifying error conditions.
|
| 955 |
|
| 956 |
[*Note 1*: `error_condition` values are portable abstractions, while
|
| 957 |
-
`error_code` values
|
| 958 |
specific. — *end note*]
|
| 959 |
|
| 960 |
``` cpp
|
| 961 |
namespace std {
|
| 962 |
class error_condition {
|
|
@@ -984,71 +914,61 @@ namespace std {
|
|
| 984 |
const error_category* cat_; // exposition only
|
| 985 |
};
|
| 986 |
}
|
| 987 |
```
|
| 988 |
|
| 989 |
-
####
|
| 990 |
|
| 991 |
``` cpp
|
| 992 |
error_condition() noexcept;
|
| 993 |
```
|
| 994 |
|
| 995 |
-
*
|
| 996 |
-
|
| 997 |
-
*Postconditions:* `val_ == 0` and `cat_ == &generic_category()`.
|
| 998 |
|
| 999 |
``` cpp
|
| 1000 |
error_condition(int val, const error_category& cat) noexcept;
|
| 1001 |
```
|
| 1002 |
|
| 1003 |
-
*
|
| 1004 |
-
|
| 1005 |
-
*Postconditions:* `val_ == val` and `cat_ == &cat`.
|
| 1006 |
|
| 1007 |
``` cpp
|
| 1008 |
template<class ErrorConditionEnum>
|
| 1009 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 1010 |
```
|
| 1011 |
|
| 1012 |
-
*
|
|
|
|
| 1013 |
|
| 1014 |
-
*
|
| 1015 |
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
This constructor shall not participate in overload resolution unless
|
| 1019 |
-
`is_error_condition_enum_v<ErrorConditionEnum>` is `true`.
|
| 1020 |
-
|
| 1021 |
-
#### Class `error_condition` modifiers <a id="syserr.errcondition.modifiers">[[syserr.errcondition.modifiers]]</a>
|
| 1022 |
|
| 1023 |
``` cpp
|
| 1024 |
void assign(int val, const error_category& cat) noexcept;
|
| 1025 |
```
|
| 1026 |
|
| 1027 |
-
*
|
| 1028 |
|
| 1029 |
``` cpp
|
| 1030 |
template<class ErrorConditionEnum>
|
| 1031 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 1032 |
```
|
| 1033 |
|
| 1034 |
-
*
|
|
|
|
|
|
|
|
|
|
| 1035 |
|
| 1036 |
*Returns:* `*this`.
|
| 1037 |
|
| 1038 |
-
*Remarks:*
|
| 1039 |
-
|
| 1040 |
-
This operator shall not participate in overload resolution unless
|
| 1041 |
-
`is_error_condition_enum_v<ErrorConditionEnum>` is `true`.
|
| 1042 |
-
|
| 1043 |
``` cpp
|
| 1044 |
void clear() noexcept;
|
| 1045 |
```
|
| 1046 |
|
| 1047 |
-
*
|
| 1048 |
|
| 1049 |
-
####
|
| 1050 |
|
| 1051 |
``` cpp
|
| 1052 |
int value() const noexcept;
|
| 1053 |
```
|
| 1054 |
|
|
@@ -1070,97 +990,93 @@ string message() const;
|
|
| 1070 |
explicit operator bool() const noexcept;
|
| 1071 |
```
|
| 1072 |
|
| 1073 |
*Returns:* `value() != 0`.
|
| 1074 |
|
| 1075 |
-
####
|
| 1076 |
|
| 1077 |
``` cpp
|
| 1078 |
error_condition make_error_condition(errc e) noexcept;
|
| 1079 |
```
|
| 1080 |
|
| 1081 |
*Returns:* `error_condition(static_cast<int>(e), generic_category())`.
|
| 1082 |
|
| 1083 |
### Comparison functions <a id="syserr.compare">[[syserr.compare]]</a>
|
| 1084 |
|
| 1085 |
-
``` cpp
|
| 1086 |
-
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 1087 |
-
```
|
| 1088 |
-
|
| 1089 |
-
*Returns:*
|
| 1090 |
-
|
| 1091 |
-
``` cpp
|
| 1092 |
-
lhs.category() < rhs.category() ||
|
| 1093 |
-
(lhs.category() == rhs.category() && lhs.value() < rhs.value());
|
| 1094 |
-
```
|
| 1095 |
-
|
| 1096 |
-
``` cpp
|
| 1097 |
-
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 1098 |
-
```
|
| 1099 |
-
|
| 1100 |
-
*Returns:*
|
| 1101 |
-
`lhs.category() < rhs.category() || lhs.category() == rhs.category() &&`
|
| 1102 |
-
`lhs.value() < rhs.value()`.
|
| 1103 |
-
|
| 1104 |
``` cpp
|
| 1105 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 1106 |
```
|
| 1107 |
|
| 1108 |
*Returns:*
|
| 1109 |
-
|
|
|
|
|
|
|
|
|
|
| 1110 |
|
| 1111 |
``` cpp
|
| 1112 |
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 1113 |
```
|
| 1114 |
|
| 1115 |
*Returns:*
|
| 1116 |
-
`lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs, rhs.value())`.
|
| 1117 |
|
| 1118 |
``` cpp
|
| 1119 |
-
|
| 1120 |
```
|
| 1121 |
|
| 1122 |
-
*Returns:*
|
| 1123 |
-
`rhs.category().equivalent(rhs.value(), lhs) || lhs.category().equivalent(rhs, lhs.value())`.
|
| 1124 |
-
|
| 1125 |
``` cpp
|
| 1126 |
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 1127 |
```
|
| 1128 |
|
| 1129 |
*Returns:*
|
| 1130 |
-
`lhs.category() == rhs.category() && lhs.value() == rhs.value()`.
|
| 1131 |
|
| 1132 |
``` cpp
|
| 1133 |
-
|
| 1134 |
-
bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 1135 |
-
bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 1136 |
-
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 1137 |
```
|
| 1138 |
|
| 1139 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1140 |
|
| 1141 |
### System error hash support <a id="syserr.hash">[[syserr.hash]]</a>
|
| 1142 |
|
| 1143 |
``` cpp
|
| 1144 |
template<> struct hash<error_code>;
|
| 1145 |
template<> struct hash<error_condition>;
|
| 1146 |
```
|
| 1147 |
|
| 1148 |
-
The specializations are enabled
|
| 1149 |
|
| 1150 |
### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
|
| 1151 |
|
| 1152 |
-
####
|
| 1153 |
|
| 1154 |
The class `system_error` describes an exception object used to report
|
| 1155 |
error conditions that have an associated error code. Such error
|
| 1156 |
conditions typically originate from the operating system or other
|
| 1157 |
low-level application program interfaces.
|
| 1158 |
|
| 1159 |
[*Note 1*: If an error represents an out-of-memory condition,
|
| 1160 |
implementations are encouraged to throw an exception object of type
|
| 1161 |
-
`bad_alloc`
|
| 1162 |
|
| 1163 |
``` cpp
|
| 1164 |
namespace std {
|
| 1165 |
class system_error : public runtime_error {
|
| 1166 |
public:
|
|
@@ -1174,67 +1090,55 @@ namespace std {
|
|
| 1174 |
const char* what() const noexcept override;
|
| 1175 |
};
|
| 1176 |
}
|
| 1177 |
```
|
| 1178 |
|
| 1179 |
-
####
|
| 1180 |
|
| 1181 |
``` cpp
|
| 1182 |
system_error(error_code ec, const string& what_arg);
|
| 1183 |
```
|
| 1184 |
|
| 1185 |
-
*
|
| 1186 |
-
|
| 1187 |
-
*Postconditions:* `code() == ec`.
|
| 1188 |
-
|
| 1189 |
-
`string(what()).find(what_arg) != string::npos`.
|
| 1190 |
|
| 1191 |
``` cpp
|
| 1192 |
system_error(error_code ec, const char* what_arg);
|
| 1193 |
```
|
| 1194 |
|
| 1195 |
-
*
|
| 1196 |
-
|
| 1197 |
-
*Postconditions:* `code() == ec`.
|
| 1198 |
-
|
| 1199 |
-
`string(what()).find(what_arg) != string::npos`.
|
| 1200 |
|
| 1201 |
``` cpp
|
| 1202 |
system_error(error_code ec);
|
| 1203 |
```
|
| 1204 |
|
| 1205 |
-
*
|
| 1206 |
-
|
| 1207 |
-
*Postconditions:* `code() == ec`.
|
| 1208 |
|
| 1209 |
``` cpp
|
| 1210 |
system_error(int ev, const error_category& ecat, const string& what_arg);
|
| 1211 |
```
|
| 1212 |
|
| 1213 |
-
*
|
| 1214 |
|
| 1215 |
-
|
| 1216 |
-
|
| 1217 |
-
`string(what()).find(what_arg) != string::npos`.
|
| 1218 |
|
| 1219 |
``` cpp
|
| 1220 |
system_error(int ev, const error_category& ecat, const char* what_arg);
|
| 1221 |
```
|
| 1222 |
|
| 1223 |
-
*
|
| 1224 |
|
| 1225 |
-
|
| 1226 |
-
|
| 1227 |
-
`string(what()).find(what_arg) != string::npos`.
|
| 1228 |
|
| 1229 |
``` cpp
|
| 1230 |
system_error(int ev, const error_category& ecat);
|
| 1231 |
```
|
| 1232 |
|
| 1233 |
-
*
|
| 1234 |
-
|
| 1235 |
-
*Postconditions:* `code() == error_code(ev, ecat)`.
|
| 1236 |
|
| 1237 |
``` cpp
|
| 1238 |
const error_code& code() const noexcept;
|
| 1239 |
```
|
| 1240 |
|
|
@@ -1252,18 +1156,19 @@ constructor.
|
|
| 1252 |
`what_arg + ": " + code.message()`. — *end note*]
|
| 1253 |
|
| 1254 |
<!-- Link reference definitions -->
|
| 1255 |
[assertions]: #assertions
|
| 1256 |
[assertions.assert]: #assertions.assert
|
| 1257 |
-
[bad.alloc]:
|
| 1258 |
[cassert.syn]: #cassert.syn
|
| 1259 |
[cerrno.syn]: #cerrno.syn
|
| 1260 |
-
[comparisons]: utilities.md#comparisons
|
| 1261 |
-
[conv]:
|
| 1262 |
[defns.const.subexpr]: library.md#defns.const.subexpr
|
| 1263 |
[diagnostics]: #diagnostics
|
| 1264 |
[diagnostics.general]: #diagnostics.general
|
|
|
|
| 1265 |
[domain.error]: #domain.error
|
| 1266 |
[errno]: #errno
|
| 1267 |
[invalid.argument]: #invalid.argument
|
| 1268 |
[length.error]: #length.error
|
| 1269 |
[logic.error]: #logic.error
|
|
@@ -1296,9 +1201,8 @@ constructor.
|
|
| 1296 |
[syserr.errcondition.overview]: #syserr.errcondition.overview
|
| 1297 |
[syserr.hash]: #syserr.hash
|
| 1298 |
[syserr.syserr]: #syserr.syserr
|
| 1299 |
[syserr.syserr.members]: #syserr.syserr.members
|
| 1300 |
[syserr.syserr.overview]: #syserr.syserr.overview
|
| 1301 |
-
[
|
| 1302 |
-
[tab:diagnostics.lib.summary]: #tab:diagnostics.lib.summary
|
| 1303 |
[underflow.error]: #underflow.error
|
| 1304 |
[unord.hash]: utilities.md#unord.hash
|
|
|
|
| 5 |
This Clause describes components that C++ programs may use to detect and
|
| 6 |
report error conditions.
|
| 7 |
|
| 8 |
The following subclauses describe components for reporting several kinds
|
| 9 |
of exceptional conditions, documenting program assertions, and a global
|
| 10 |
+
variable for error number codes, as summarized in
|
| 11 |
+
[[diagnostics.summary]].
|
| 12 |
|
| 13 |
+
**Table: Diagnostics library summary** <a id="diagnostics.summary">[diagnostics.summary]</a>
|
| 14 |
|
| 15 |
| Subclause | | Header |
|
| 16 |
| ------------------ | -------------------- | ---------------- |
|
| 17 |
| [[std.exceptions]] | Exception classes | `<stdexcept>` |
|
| 18 |
| [[assertions]] | Assertions | `<cassert>` |
|
|
|
|
| 21 |
|
| 22 |
|
| 23 |
## Exception classes <a id="std.exceptions">[[std.exceptions]]</a>
|
| 24 |
|
| 25 |
The C++ standard library provides classes to be used to report certain
|
| 26 |
+
errors [[res.on.exception.handling]] in C++ programs. In the error model
|
| 27 |
+
reflected in these classes, errors are divided into two broad
|
| 28 |
categories: *logic* errors and *runtime* errors.
|
| 29 |
|
| 30 |
The distinguishing characteristic of logic errors is that they are due
|
| 31 |
to errors in the internal logic of the program. In theory, they are
|
| 32 |
preventable.
|
|
|
|
| 71 |
|
| 72 |
``` cpp
|
| 73 |
logic_error(const string& what_arg);
|
| 74 |
```
|
| 75 |
|
| 76 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 77 |
|
| 78 |
``` cpp
|
| 79 |
logic_error(const char* what_arg);
|
| 80 |
```
|
| 81 |
|
| 82 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 83 |
|
| 84 |
### Class `domain_error` <a id="domain.error">[[domain.error]]</a>
|
| 85 |
|
| 86 |
``` cpp
|
| 87 |
namespace std {
|
|
|
|
| 98 |
|
| 99 |
``` cpp
|
| 100 |
domain_error(const string& what_arg);
|
| 101 |
```
|
| 102 |
|
| 103 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 104 |
|
| 105 |
``` cpp
|
| 106 |
domain_error(const char* what_arg);
|
| 107 |
```
|
| 108 |
|
| 109 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 110 |
|
| 111 |
### Class `invalid_argument` <a id="invalid.argument">[[invalid.argument]]</a>
|
| 112 |
|
| 113 |
``` cpp
|
| 114 |
namespace std {
|
|
|
|
| 125 |
|
| 126 |
``` cpp
|
| 127 |
invalid_argument(const string& what_arg);
|
| 128 |
```
|
| 129 |
|
| 130 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 131 |
|
| 132 |
``` cpp
|
| 133 |
invalid_argument(const char* what_arg);
|
| 134 |
```
|
| 135 |
|
| 136 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 137 |
|
| 138 |
### Class `length_error` <a id="length.error">[[length.error]]</a>
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
namespace std {
|
|
|
|
| 153 |
|
| 154 |
``` cpp
|
| 155 |
length_error(const string& what_arg);
|
| 156 |
```
|
| 157 |
|
| 158 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 159 |
|
| 160 |
``` cpp
|
| 161 |
length_error(const char* what_arg);
|
| 162 |
```
|
| 163 |
|
| 164 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 165 |
|
| 166 |
### Class `out_of_range` <a id="out.of.range">[[out.of.range]]</a>
|
| 167 |
|
| 168 |
``` cpp
|
| 169 |
namespace std {
|
|
|
|
| 180 |
|
| 181 |
``` cpp
|
| 182 |
out_of_range(const string& what_arg);
|
| 183 |
```
|
| 184 |
|
| 185 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 186 |
|
| 187 |
``` cpp
|
| 188 |
out_of_range(const char* what_arg);
|
| 189 |
```
|
| 190 |
|
| 191 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 192 |
|
| 193 |
### Class `runtime_error` <a id="runtime.error">[[runtime.error]]</a>
|
| 194 |
|
| 195 |
``` cpp
|
| 196 |
namespace std {
|
|
|
|
| 208 |
|
| 209 |
``` cpp
|
| 210 |
runtime_error(const string& what_arg);
|
| 211 |
```
|
| 212 |
|
| 213 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 214 |
|
| 215 |
``` cpp
|
| 216 |
runtime_error(const char* what_arg);
|
| 217 |
```
|
| 218 |
|
| 219 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 220 |
|
| 221 |
### Class `range_error` <a id="range.error">[[range.error]]</a>
|
| 222 |
|
| 223 |
``` cpp
|
| 224 |
namespace std {
|
|
|
|
| 235 |
|
| 236 |
``` cpp
|
| 237 |
range_error(const string& what_arg);
|
| 238 |
```
|
| 239 |
|
| 240 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 241 |
|
| 242 |
``` cpp
|
| 243 |
range_error(const char* what_arg);
|
| 244 |
```
|
| 245 |
|
| 246 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 247 |
|
| 248 |
### Class `overflow_error` <a id="overflow.error">[[overflow.error]]</a>
|
| 249 |
|
| 250 |
``` cpp
|
| 251 |
namespace std {
|
|
|
|
| 262 |
|
| 263 |
``` cpp
|
| 264 |
overflow_error(const string& what_arg);
|
| 265 |
```
|
| 266 |
|
| 267 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 268 |
|
| 269 |
``` cpp
|
| 270 |
overflow_error(const char* what_arg);
|
| 271 |
```
|
| 272 |
|
| 273 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 274 |
|
| 275 |
### Class `underflow_error` <a id="underflow.error">[[underflow.error]]</a>
|
| 276 |
|
| 277 |
``` cpp
|
| 278 |
namespace std {
|
|
|
|
| 289 |
|
| 290 |
``` cpp
|
| 291 |
underflow_error(const string& what_arg);
|
| 292 |
```
|
| 293 |
|
| 294 |
+
*Ensures:* `strcmp(what(), what_arg.c_str()) == 0`.
|
|
|
|
|
|
|
| 295 |
|
| 296 |
``` cpp
|
| 297 |
underflow_error(const char* what_arg);
|
| 298 |
```
|
| 299 |
|
| 300 |
+
*Ensures:* `strcmp(what(), what_arg) == 0`.
|
|
|
|
|
|
|
| 301 |
|
| 302 |
## Assertions <a id="assertions">[[assertions]]</a>
|
| 303 |
|
| 304 |
The header `<cassert>` provides a macro for documenting C++ program
|
| 305 |
assertions and a mechanism for disabling the assertion checks.
|
|
|
|
| 311 |
```
|
| 312 |
|
| 313 |
The contents are the same as the C standard library header `<assert.h>`,
|
| 314 |
except that a macro named `static_assert` is not defined.
|
| 315 |
|
| 316 |
+
See also: ISO C 7.2
|
| 317 |
|
| 318 |
### The `assert` macro <a id="assertions.assert">[[assertions.assert]]</a>
|
| 319 |
|
| 320 |
+
An expression `assert(E)` is a constant subexpression
|
| 321 |
+
[[defns.const.subexpr]], if
|
| 322 |
|
| 323 |
- `NDEBUG` is defined at the point where `assert` is last defined or
|
| 324 |
redefined, or
|
| 325 |
+
- `E` contextually converted to `bool` [[conv]] is a constant
|
| 326 |
subexpression that evaluates to the value `true`.
|
| 327 |
|
| 328 |
## Error numbers <a id="errno">[[errno]]</a>
|
| 329 |
|
| 330 |
The contents of the header `<cerrno>` are the same as the POSIX header
|
|
|
|
| 421 |
```
|
| 422 |
|
| 423 |
The meaning of the macros in this header is defined by the POSIX
|
| 424 |
standard.
|
| 425 |
|
| 426 |
+
See also: ISO C 7.5
|
| 427 |
|
| 428 |
## System error support <a id="syserr">[[syserr]]</a>
|
| 429 |
|
| 430 |
+
This subclause describes components that the standard library and C++
|
| 431 |
+
programs may use to report error conditions originating from the
|
| 432 |
operating system or other low-level application program interfaces.
|
| 433 |
|
| 434 |
Components described in this subclause shall not change the value of
|
| 435 |
+
`errno` [[errno]]. Implementations should leave the error states
|
| 436 |
provided by other libraries unchanged.
|
| 437 |
|
| 438 |
+
### Header `<system_error>` synopsis <a id="system.error.syn">[[system.error.syn]]</a>
|
| 439 |
|
| 440 |
``` cpp
|
| 441 |
+
#include <compare> // see [compare.syn]
|
| 442 |
+
|
| 443 |
namespace std {
|
| 444 |
class error_category;
|
| 445 |
const error_category& generic_category() noexcept;
|
| 446 |
const error_category& system_category() noexcept;
|
| 447 |
|
|
|
|
| 547 |
|
| 548 |
// [syserr.errcondition.nonmembers], non-member functions
|
| 549 |
error_condition make_error_condition(errc e) noexcept;
|
| 550 |
|
| 551 |
// [syserr.compare], comparison functions
|
|
|
|
|
|
|
| 552 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 553 |
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
|
|
|
|
| 554 |
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 555 |
+
strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept;
|
| 556 |
+
strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept;
|
|
|
|
|
|
|
| 557 |
|
| 558 |
// [syserr.hash], hash support
|
| 559 |
template<class T> struct hash;
|
| 560 |
template<> struct hash<error_code>;
|
| 561 |
template<> struct hash<error_condition>;
|
| 562 |
|
| 563 |
// [syserr], system error support
|
| 564 |
+
template<class T>
|
| 565 |
+
inline constexpr bool is_error_code_enum_v = is_error_code_enum<T>::value;
|
| 566 |
+
template<class T>
|
| 567 |
+
inline constexpr bool is_error_condition_enum_v = is_error_condition_enum<T>::value;
|
| 568 |
}
|
| 569 |
```
|
| 570 |
|
| 571 |
The value of each `enum errc` constant shall be the same as the value of
|
| 572 |
the `<cerrno>` macro shown in the above synopsis. Whether or not the
|
| 573 |
`<system_error>` implementation exposes the `<cerrno>` macros is
|
| 574 |
unspecified.
|
| 575 |
|
| 576 |
The `is_error_code_enum` and `is_error_condition_enum` may be
|
| 577 |
+
specialized for program-defined types to indicate that such types are
|
| 578 |
eligible for `class error_code` and `class error_condition` automatic
|
| 579 |
conversions, respectively.
|
| 580 |
|
| 581 |
### Class `error_category` <a id="syserr.errcat">[[syserr.errcat]]</a>
|
| 582 |
|
| 583 |
+
#### Overview <a id="syserr.errcat.overview">[[syserr.errcat.overview]]</a>
|
| 584 |
|
| 585 |
The class `error_category` serves as a base class for types used to
|
| 586 |
identify the source and encoding of a particular category of error code.
|
| 587 |
Classes may be derived from `error_category` to support categories of
|
| 588 |
+
errors in addition to those defined in this document. Such classes shall
|
| 589 |
+
behave as specified in subclause [[syserr.errcat]].
|
| 590 |
|
| 591 |
[*Note 1*: `error_category` objects are passed by reference, and two
|
| 592 |
such objects are equal if they have the same address. This means that
|
| 593 |
applications using custom `error_category` types should create a single
|
| 594 |
object of each such type. — *end note*]
|
|
|
|
| 606 |
virtual bool equivalent(int code, const error_condition& condition) const noexcept;
|
| 607 |
virtual bool equivalent(const error_code& code, int condition) const noexcept;
|
| 608 |
virtual string message(int ev) const = 0;
|
| 609 |
|
| 610 |
bool operator==(const error_category& rhs) const noexcept;
|
| 611 |
+
strong_ordering operator<=>(const error_category& rhs) const noexcept;
|
|
|
|
| 612 |
};
|
| 613 |
|
| 614 |
const error_category& generic_category() noexcept;
|
| 615 |
const error_category& system_category() noexcept;
|
| 616 |
}
|
| 617 |
```
|
| 618 |
|
| 619 |
+
#### Virtual members <a id="syserr.errcat.virtuals">[[syserr.errcat.virtuals]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 620 |
|
| 621 |
``` cpp
|
| 622 |
virtual const char* name() const noexcept = 0;
|
| 623 |
```
|
| 624 |
|
|
|
|
| 646 |
virtual string message(int ev) const = 0;
|
| 647 |
```
|
| 648 |
|
| 649 |
*Returns:* A string that describes the error condition denoted by `ev`.
|
| 650 |
|
| 651 |
+
#### Non-virtual members <a id="syserr.errcat.nonvirtuals">[[syserr.errcat.nonvirtuals]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 652 |
|
| 653 |
``` cpp
|
| 654 |
bool operator==(const error_category& rhs) const noexcept;
|
| 655 |
```
|
| 656 |
|
| 657 |
*Returns:* `this == &rhs`.
|
| 658 |
|
| 659 |
``` cpp
|
| 660 |
+
strong_ordering operator<=>(const error_category& rhs) const noexcept;
|
| 661 |
```
|
| 662 |
|
| 663 |
+
*Returns:* `compare_three_way()(this, &rhs)`.
|
| 664 |
|
| 665 |
+
[*Note 1*: `compare_three_way` [[comparisons.three.way]] provides a
|
| 666 |
+
total ordering for pointers. — *end note*]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 667 |
|
| 668 |
+
#### Program-defined classes derived from `error_category` <a id="syserr.errcat.derived">[[syserr.errcat.derived]]</a>
|
| 669 |
|
| 670 |
``` cpp
|
| 671 |
virtual const char* name() const noexcept = 0;
|
| 672 |
```
|
| 673 |
|
|
|
|
| 732 |
implementations are given latitude in determining
|
| 733 |
correspondence. — *end note*]
|
| 734 |
|
| 735 |
### Class `error_code` <a id="syserr.errcode">[[syserr.errcode]]</a>
|
| 736 |
|
| 737 |
+
#### Overview <a id="syserr.errcode.overview">[[syserr.errcode.overview]]</a>
|
| 738 |
|
| 739 |
The class `error_code` describes an object used to hold error code
|
| 740 |
values, such as those originating from the operating system or other
|
| 741 |
low-level application program interfaces.
|
| 742 |
|
|
|
|
| 778 |
basic_ostream<charT, traits>&
|
| 779 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 780 |
}
|
| 781 |
```
|
| 782 |
|
| 783 |
+
#### Constructors <a id="syserr.errcode.constructors">[[syserr.errcode.constructors]]</a>
|
| 784 |
|
| 785 |
``` cpp
|
| 786 |
error_code() noexcept;
|
| 787 |
```
|
| 788 |
|
| 789 |
+
*Ensures:* `val_ == 0` and `cat_ == &system_category()`.
|
|
|
|
|
|
|
| 790 |
|
| 791 |
``` cpp
|
| 792 |
error_code(int val, const error_category& cat) noexcept;
|
| 793 |
```
|
| 794 |
|
| 795 |
+
*Ensures:* `val_ == val` and `cat_ == &cat`.
|
|
|
|
|
|
|
| 796 |
|
| 797 |
``` cpp
|
| 798 |
template<class ErrorCodeEnum>
|
| 799 |
error_code(ErrorCodeEnum e) noexcept;
|
| 800 |
```
|
| 801 |
|
| 802 |
+
*Constraints:* `is_error_code_enum_v<ErrorCodeEnum>` is `true`.
|
| 803 |
|
| 804 |
+
*Ensures:* `*this == make_error_code(e)`.
|
| 805 |
|
| 806 |
+
#### Modifiers <a id="syserr.errcode.modifiers">[[syserr.errcode.modifiers]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 807 |
|
| 808 |
``` cpp
|
| 809 |
void assign(int val, const error_category& cat) noexcept;
|
| 810 |
```
|
| 811 |
|
| 812 |
+
*Ensures:* `val_ == val` and `cat_ == &cat`.
|
| 813 |
|
| 814 |
``` cpp
|
| 815 |
template<class ErrorCodeEnum>
|
| 816 |
error_code& operator=(ErrorCodeEnum e) noexcept;
|
| 817 |
```
|
| 818 |
|
| 819 |
+
*Constraints:* `is_error_code_enum_v<ErrorCodeEnum>` is `true`.
|
| 820 |
+
|
| 821 |
+
*Ensures:* `*this == make_error_code(e)`.
|
| 822 |
|
| 823 |
*Returns:* `*this`.
|
| 824 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 825 |
``` cpp
|
| 826 |
void clear() noexcept;
|
| 827 |
```
|
| 828 |
|
| 829 |
+
*Ensures:* `value() == 0` and `category() == system_category()`.
|
| 830 |
|
| 831 |
+
#### Observers <a id="syserr.errcode.observers">[[syserr.errcode.observers]]</a>
|
| 832 |
|
| 833 |
``` cpp
|
| 834 |
int value() const noexcept;
|
| 835 |
```
|
| 836 |
|
|
|
|
| 858 |
explicit operator bool() const noexcept;
|
| 859 |
```
|
| 860 |
|
| 861 |
*Returns:* `value() != 0`.
|
| 862 |
|
| 863 |
+
#### Non-member functions <a id="syserr.errcode.nonmembers">[[syserr.errcode.nonmembers]]</a>
|
| 864 |
|
| 865 |
``` cpp
|
| 866 |
error_code make_error_code(errc e) noexcept;
|
| 867 |
```
|
| 868 |
|
| 869 |
*Returns:* `error_code(static_cast<int>(e), generic_category())`.
|
| 870 |
|
| 871 |
``` cpp
|
| 872 |
template<class charT, class traits>
|
| 873 |
+
basic_ostream<charT, traits>& operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
|
|
|
| 874 |
```
|
| 875 |
|
| 876 |
+
*Effects:* Equivalent to:
|
| 877 |
+
`return os << ec.category().name() << ’:’ << ec.value();`
|
| 878 |
|
| 879 |
### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
|
| 880 |
|
| 881 |
+
#### Overview <a id="syserr.errcondition.overview">[[syserr.errcondition.overview]]</a>
|
| 882 |
|
| 883 |
The class `error_condition` describes an object used to hold values
|
| 884 |
identifying error conditions.
|
| 885 |
|
| 886 |
[*Note 1*: `error_condition` values are portable abstractions, while
|
| 887 |
+
`error_code` values [[syserr.errcode]] are implementation
|
| 888 |
specific. — *end note*]
|
| 889 |
|
| 890 |
``` cpp
|
| 891 |
namespace std {
|
| 892 |
class error_condition {
|
|
|
|
| 914 |
const error_category* cat_; // exposition only
|
| 915 |
};
|
| 916 |
}
|
| 917 |
```
|
| 918 |
|
| 919 |
+
#### Constructors <a id="syserr.errcondition.constructors">[[syserr.errcondition.constructors]]</a>
|
| 920 |
|
| 921 |
``` cpp
|
| 922 |
error_condition() noexcept;
|
| 923 |
```
|
| 924 |
|
| 925 |
+
*Ensures:* `val_ == 0` and `cat_ == &generic_category()`.
|
|
|
|
|
|
|
| 926 |
|
| 927 |
``` cpp
|
| 928 |
error_condition(int val, const error_category& cat) noexcept;
|
| 929 |
```
|
| 930 |
|
| 931 |
+
*Ensures:* `val_ == val` and `cat_ == &cat`.
|
|
|
|
|
|
|
| 932 |
|
| 933 |
``` cpp
|
| 934 |
template<class ErrorConditionEnum>
|
| 935 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 936 |
```
|
| 937 |
|
| 938 |
+
*Constraints:* `is_error_condition_enum_v<ErrorConditionEnum>` is
|
| 939 |
+
`true`.
|
| 940 |
|
| 941 |
+
*Ensures:* `*this == make_error_condition(e)`.
|
| 942 |
|
| 943 |
+
#### Modifiers <a id="syserr.errcondition.modifiers">[[syserr.errcondition.modifiers]]</a>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 944 |
|
| 945 |
``` cpp
|
| 946 |
void assign(int val, const error_category& cat) noexcept;
|
| 947 |
```
|
| 948 |
|
| 949 |
+
*Ensures:* `val_ == val` and `cat_ == &cat`.
|
| 950 |
|
| 951 |
``` cpp
|
| 952 |
template<class ErrorConditionEnum>
|
| 953 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 954 |
```
|
| 955 |
|
| 956 |
+
*Constraints:* `is_error_condition_enum_v<ErrorConditionEnum>` is
|
| 957 |
+
`true`.
|
| 958 |
+
|
| 959 |
+
*Ensures:* `*this == make_error_condition(e)`.
|
| 960 |
|
| 961 |
*Returns:* `*this`.
|
| 962 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 963 |
``` cpp
|
| 964 |
void clear() noexcept;
|
| 965 |
```
|
| 966 |
|
| 967 |
+
*Ensures:* `value() == 0` and `category() == generic_category()`.
|
| 968 |
|
| 969 |
+
#### Observers <a id="syserr.errcondition.observers">[[syserr.errcondition.observers]]</a>
|
| 970 |
|
| 971 |
``` cpp
|
| 972 |
int value() const noexcept;
|
| 973 |
```
|
| 974 |
|
|
|
|
| 990 |
explicit operator bool() const noexcept;
|
| 991 |
```
|
| 992 |
|
| 993 |
*Returns:* `value() != 0`.
|
| 994 |
|
| 995 |
+
#### Non-member functions <a id="syserr.errcondition.nonmembers">[[syserr.errcondition.nonmembers]]</a>
|
| 996 |
|
| 997 |
``` cpp
|
| 998 |
error_condition make_error_condition(errc e) noexcept;
|
| 999 |
```
|
| 1000 |
|
| 1001 |
*Returns:* `error_condition(static_cast<int>(e), generic_category())`.
|
| 1002 |
|
| 1003 |
### Comparison functions <a id="syserr.compare">[[syserr.compare]]</a>
|
| 1004 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1005 |
``` cpp
|
| 1006 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 1007 |
```
|
| 1008 |
|
| 1009 |
*Returns:*
|
| 1010 |
+
|
| 1011 |
+
``` cpp
|
| 1012 |
+
lhs.category() == rhs.category() && lhs.value() == rhs.value()
|
| 1013 |
+
```
|
| 1014 |
|
| 1015 |
``` cpp
|
| 1016 |
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 1017 |
```
|
| 1018 |
|
| 1019 |
*Returns:*
|
|
|
|
| 1020 |
|
| 1021 |
``` cpp
|
| 1022 |
+
lhs.category().equivalent(lhs.value(), rhs) || rhs.category().equivalent(lhs, rhs.value())
|
| 1023 |
```
|
| 1024 |
|
|
|
|
|
|
|
|
|
|
| 1025 |
``` cpp
|
| 1026 |
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 1027 |
```
|
| 1028 |
|
| 1029 |
*Returns:*
|
|
|
|
| 1030 |
|
| 1031 |
``` cpp
|
| 1032 |
+
lhs.category() == rhs.category() && lhs.value() == rhs.value()
|
|
|
|
|
|
|
|
|
|
| 1033 |
```
|
| 1034 |
|
| 1035 |
+
``` cpp
|
| 1036 |
+
strong_ordering operator<=>(const error_code& lhs, const error_code& rhs) noexcept;
|
| 1037 |
+
```
|
| 1038 |
+
|
| 1039 |
+
*Effects:* Equivalent to:
|
| 1040 |
+
|
| 1041 |
+
``` cpp
|
| 1042 |
+
if (auto c = lhs.category() <=> rhs.category(); c != 0) return c;
|
| 1043 |
+
return lhs.value() <=> rhs.value();
|
| 1044 |
+
```
|
| 1045 |
+
|
| 1046 |
+
``` cpp
|
| 1047 |
+
strong_ordering operator<=>(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 1048 |
+
```
|
| 1049 |
+
|
| 1050 |
+
*Returns:*
|
| 1051 |
+
|
| 1052 |
+
``` cpp
|
| 1053 |
+
if (auto c = lhs.category() <=> rhs.category(); c != 0) return c;
|
| 1054 |
+
return lhs.value() <=> rhs.value();
|
| 1055 |
+
```
|
| 1056 |
|
| 1057 |
### System error hash support <a id="syserr.hash">[[syserr.hash]]</a>
|
| 1058 |
|
| 1059 |
``` cpp
|
| 1060 |
template<> struct hash<error_code>;
|
| 1061 |
template<> struct hash<error_condition>;
|
| 1062 |
```
|
| 1063 |
|
| 1064 |
+
The specializations are enabled [[unord.hash]].
|
| 1065 |
|
| 1066 |
### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
|
| 1067 |
|
| 1068 |
+
#### Overview <a id="syserr.syserr.overview">[[syserr.syserr.overview]]</a>
|
| 1069 |
|
| 1070 |
The class `system_error` describes an exception object used to report
|
| 1071 |
error conditions that have an associated error code. Such error
|
| 1072 |
conditions typically originate from the operating system or other
|
| 1073 |
low-level application program interfaces.
|
| 1074 |
|
| 1075 |
[*Note 1*: If an error represents an out-of-memory condition,
|
| 1076 |
implementations are encouraged to throw an exception object of type
|
| 1077 |
+
`bad_alloc` [[bad.alloc]] rather than `system_error`. — *end note*]
|
| 1078 |
|
| 1079 |
``` cpp
|
| 1080 |
namespace std {
|
| 1081 |
class system_error : public runtime_error {
|
| 1082 |
public:
|
|
|
|
| 1090 |
const char* what() const noexcept override;
|
| 1091 |
};
|
| 1092 |
}
|
| 1093 |
```
|
| 1094 |
|
| 1095 |
+
#### Members <a id="syserr.syserr.members">[[syserr.syserr.members]]</a>
|
| 1096 |
|
| 1097 |
``` cpp
|
| 1098 |
system_error(error_code ec, const string& what_arg);
|
| 1099 |
```
|
| 1100 |
|
| 1101 |
+
*Ensures:* `code() == ec` and
|
| 1102 |
+
`string_view(what()).find(what_arg.c_str()) != string_view::npos`.
|
|
|
|
|
|
|
|
|
|
| 1103 |
|
| 1104 |
``` cpp
|
| 1105 |
system_error(error_code ec, const char* what_arg);
|
| 1106 |
```
|
| 1107 |
|
| 1108 |
+
*Ensures:* `code() == ec` and
|
| 1109 |
+
`string_view(what()).find(what_arg) != string_view::npos`.
|
|
|
|
|
|
|
|
|
|
| 1110 |
|
| 1111 |
``` cpp
|
| 1112 |
system_error(error_code ec);
|
| 1113 |
```
|
| 1114 |
|
| 1115 |
+
*Ensures:* `code() == ec`.
|
|
|
|
|
|
|
| 1116 |
|
| 1117 |
``` cpp
|
| 1118 |
system_error(int ev, const error_category& ecat, const string& what_arg);
|
| 1119 |
```
|
| 1120 |
|
| 1121 |
+
*Ensures:*
|
| 1122 |
|
| 1123 |
+
`code() == error_code(ev, ecat)` and
|
| 1124 |
+
`string_view(what()).find(what_arg.c_str()) != string_view::npos`.
|
|
|
|
| 1125 |
|
| 1126 |
``` cpp
|
| 1127 |
system_error(int ev, const error_category& ecat, const char* what_arg);
|
| 1128 |
```
|
| 1129 |
|
| 1130 |
+
*Ensures:*
|
| 1131 |
|
| 1132 |
+
`code() == error_code(ev, ecat)` and
|
| 1133 |
+
`string_view(what()).find(what_arg) != string_view::npos`.
|
|
|
|
| 1134 |
|
| 1135 |
``` cpp
|
| 1136 |
system_error(int ev, const error_category& ecat);
|
| 1137 |
```
|
| 1138 |
|
| 1139 |
+
*Ensures:* `code() == error_code(ev, ecat)`.
|
|
|
|
|
|
|
| 1140 |
|
| 1141 |
``` cpp
|
| 1142 |
const error_code& code() const noexcept;
|
| 1143 |
```
|
| 1144 |
|
|
|
|
| 1156 |
`what_arg + ": " + code.message()`. — *end note*]
|
| 1157 |
|
| 1158 |
<!-- Link reference definitions -->
|
| 1159 |
[assertions]: #assertions
|
| 1160 |
[assertions.assert]: #assertions.assert
|
| 1161 |
+
[bad.alloc]: support.md#bad.alloc
|
| 1162 |
[cassert.syn]: #cassert.syn
|
| 1163 |
[cerrno.syn]: #cerrno.syn
|
| 1164 |
+
[comparisons.three.way]: utilities.md#comparisons.three.way
|
| 1165 |
+
[conv]: expr.md#conv
|
| 1166 |
[defns.const.subexpr]: library.md#defns.const.subexpr
|
| 1167 |
[diagnostics]: #diagnostics
|
| 1168 |
[diagnostics.general]: #diagnostics.general
|
| 1169 |
+
[diagnostics.summary]: #diagnostics.summary
|
| 1170 |
[domain.error]: #domain.error
|
| 1171 |
[errno]: #errno
|
| 1172 |
[invalid.argument]: #invalid.argument
|
| 1173 |
[length.error]: #length.error
|
| 1174 |
[logic.error]: #logic.error
|
|
|
|
| 1201 |
[syserr.errcondition.overview]: #syserr.errcondition.overview
|
| 1202 |
[syserr.hash]: #syserr.hash
|
| 1203 |
[syserr.syserr]: #syserr.syserr
|
| 1204 |
[syserr.syserr.members]: #syserr.syserr.members
|
| 1205 |
[syserr.syserr.overview]: #syserr.syserr.overview
|
| 1206 |
+
[system.error.syn]: #system.error.syn
|
|
|
|
| 1207 |
[underflow.error]: #underflow.error
|
| 1208 |
[unord.hash]: utilities.md#unord.hash
|