- tmp/tmp2dbgg5wc/{from.md → to.md} +247 -104
tmp/tmp2dbgg5wc/{from.md → to.md}
RENAMED
|
@@ -20,11 +20,11 @@ variable for error number codes, as summarized in Table
|
|
| 20 |
| [[syserr]] | System error support | `<system_error>` |
|
| 21 |
|
| 22 |
|
| 23 |
## Exception classes <a id="std.exceptions">[[std.exceptions]]</a>
|
| 24 |
|
| 25 |
-
The
|
| 26 |
errors ([[res.on.exception.handling]]) in C++programs. In the error
|
| 27 |
model 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
|
|
@@ -35,10 +35,12 @@ By contrast, runtime errors are due to events beyond the scope of the
|
|
| 35 |
program. They cannot be easily predicted in advance. The header
|
| 36 |
`<stdexcept>` defines several types of predefined exceptions for
|
| 37 |
reporting errors in a C++program. These exceptions are related by
|
| 38 |
inheritance.
|
| 39 |
|
|
|
|
|
|
|
| 40 |
``` cpp
|
| 41 |
namespace std {
|
| 42 |
class logic_error;
|
| 43 |
class domain_error;
|
| 44 |
class invalid_argument;
|
|
@@ -71,19 +73,19 @@ as violations of logical preconditions or class invariants.
|
|
| 71 |
logic_error(const string& what_arg);
|
| 72 |
```
|
| 73 |
|
| 74 |
*Effects:* Constructs an object of class `logic_error`.
|
| 75 |
|
| 76 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 77 |
|
| 78 |
``` cpp
|
| 79 |
logic_error(const char* what_arg);
|
| 80 |
```
|
| 81 |
|
| 82 |
*Effects:* Constructs an object of class `logic_error`.
|
| 83 |
|
| 84 |
-
`strcmp(what(), what_arg) == 0`.
|
| 85 |
|
| 86 |
### Class `domain_error` <a id="domain.error">[[domain.error]]</a>
|
| 87 |
|
| 88 |
``` cpp
|
| 89 |
namespace std {
|
|
@@ -102,19 +104,19 @@ exceptions by the implementation to report domain errors.
|
|
| 102 |
domain_error(const string& what_arg);
|
| 103 |
```
|
| 104 |
|
| 105 |
*Effects:* Constructs an object of class `domain_error`.
|
| 106 |
|
| 107 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 108 |
|
| 109 |
``` cpp
|
| 110 |
domain_error(const char* what_arg);
|
| 111 |
```
|
| 112 |
|
| 113 |
*Effects:* Constructs an object of class `domain_error`.
|
| 114 |
|
| 115 |
-
`strcmp(what(), what_arg) == 0`.
|
| 116 |
|
| 117 |
### Class `invalid_argument` <a id="invalid.argument">[[invalid.argument]]</a>
|
| 118 |
|
| 119 |
``` cpp
|
| 120 |
namespace std {
|
|
@@ -133,19 +135,19 @@ exceptions to report an invalid argument.
|
|
| 133 |
invalid_argument(const string& what_arg);
|
| 134 |
```
|
| 135 |
|
| 136 |
*Effects:* Constructs an object of class `invalid_argument`.
|
| 137 |
|
| 138 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 139 |
|
| 140 |
``` cpp
|
| 141 |
invalid_argument(const char* what_arg);
|
| 142 |
```
|
| 143 |
|
| 144 |
*Effects:* Constructs an object of class `invalid_argument`.
|
| 145 |
|
| 146 |
-
`strcmp(what(), what_arg) == 0`.
|
| 147 |
|
| 148 |
### Class `length_error` <a id="length.error">[[length.error]]</a>
|
| 149 |
|
| 150 |
``` cpp
|
| 151 |
namespace std {
|
|
@@ -165,19 +167,19 @@ exceeds its maximum allowable size.
|
|
| 165 |
length_error(const string& what_arg);
|
| 166 |
```
|
| 167 |
|
| 168 |
*Effects:* Constructs an object of class `length_error`.
|
| 169 |
|
| 170 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 171 |
|
| 172 |
``` cpp
|
| 173 |
length_error(const char* what_arg);
|
| 174 |
```
|
| 175 |
|
| 176 |
*Effects:* Constructs an object of class `length_error`.
|
| 177 |
|
| 178 |
-
`strcmp(what(), what_arg) == 0`.
|
| 179 |
|
| 180 |
### Class `out_of_range` <a id="out.of.range">[[out.of.range]]</a>
|
| 181 |
|
| 182 |
``` cpp
|
| 183 |
namespace std {
|
|
@@ -196,19 +198,19 @@ exceptions to report an argument value not in its expected range.
|
|
| 196 |
out_of_range(const string& what_arg);
|
| 197 |
```
|
| 198 |
|
| 199 |
*Effects:* Constructs an object of class `out_of_range`.
|
| 200 |
|
| 201 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 202 |
|
| 203 |
``` cpp
|
| 204 |
out_of_range(const char* what_arg);
|
| 205 |
```
|
| 206 |
|
| 207 |
*Effects:* Constructs an object of class `out_of_range`.
|
| 208 |
|
| 209 |
-
`strcmp(what(), what_arg) == 0`.
|
| 210 |
|
| 211 |
### Class `runtime_error` <a id="runtime.error">[[runtime.error]]</a>
|
| 212 |
|
| 213 |
``` cpp
|
| 214 |
namespace std {
|
|
@@ -228,19 +230,19 @@ executes.
|
|
| 228 |
runtime_error(const string& what_arg);
|
| 229 |
```
|
| 230 |
|
| 231 |
*Effects:* Constructs an object of class `runtime_error`.
|
| 232 |
|
| 233 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 234 |
|
| 235 |
``` cpp
|
| 236 |
runtime_error(const char* what_arg);
|
| 237 |
```
|
| 238 |
|
| 239 |
*Effects:* Constructs an object of class `runtime_error`.
|
| 240 |
|
| 241 |
-
`strcmp(what(), what_arg) == 0`.
|
| 242 |
|
| 243 |
### Class `range_error` <a id="range.error">[[range.error]]</a>
|
| 244 |
|
| 245 |
``` cpp
|
| 246 |
namespace std {
|
|
@@ -259,19 +261,19 @@ to report range errors in internal computations.
|
|
| 259 |
range_error(const string& what_arg);
|
| 260 |
```
|
| 261 |
|
| 262 |
*Effects:* Constructs an object of class `range_error`.
|
| 263 |
|
| 264 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 265 |
|
| 266 |
``` cpp
|
| 267 |
range_error(const char* what_arg);
|
| 268 |
```
|
| 269 |
|
| 270 |
*Effects:* Constructs an object of class `range_error`.
|
| 271 |
|
| 272 |
-
`strcmp(what(), what_arg) == 0`.
|
| 273 |
|
| 274 |
### Class `overflow_error` <a id="overflow.error">[[overflow.error]]</a>
|
| 275 |
|
| 276 |
``` cpp
|
| 277 |
namespace std {
|
|
@@ -290,19 +292,19 @@ exceptions to report an arithmetic overflow error.
|
|
| 290 |
overflow_error(const string& what_arg);
|
| 291 |
```
|
| 292 |
|
| 293 |
*Effects:* Constructs an object of class `overflow_error`.
|
| 294 |
|
| 295 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 296 |
|
| 297 |
``` cpp
|
| 298 |
overflow_error(const char* what_arg);
|
| 299 |
```
|
| 300 |
|
| 301 |
*Effects:* Constructs an object of class `overflow_error`.
|
| 302 |
|
| 303 |
-
`strcmp(what(), what_arg) == 0`.
|
| 304 |
|
| 305 |
### Class `underflow_error` <a id="underflow.error">[[underflow.error]]</a>
|
| 306 |
|
| 307 |
``` cpp
|
| 308 |
namespace std {
|
|
@@ -321,38 +323,145 @@ exceptions to report an arithmetic underflow error.
|
|
| 321 |
underflow_error(const string& what_arg);
|
| 322 |
```
|
| 323 |
|
| 324 |
*Effects:* Constructs an object of class `underflow_error`.
|
| 325 |
|
| 326 |
-
`strcmp(what(), what_arg.c_str()) == 0`.
|
| 327 |
|
| 328 |
``` cpp
|
| 329 |
underflow_error(const char* what_arg);
|
| 330 |
```
|
| 331 |
|
| 332 |
*Effects:* Constructs an object of class `underflow_error`.
|
| 333 |
|
| 334 |
-
`strcmp(what(), what_arg) == 0`.
|
| 335 |
|
| 336 |
## Assertions <a id="assertions">[[assertions]]</a>
|
| 337 |
|
| 338 |
-
The header `<cassert>`
|
| 339 |
-
|
| 340 |
-
C++program assertions and a mechanism for disabling the assertion
|
| 341 |
-
checks.
|
| 342 |
|
| 343 |
-
|
| 344 |
|
| 345 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
## Error numbers <a id="errno">[[errno]]</a>
|
| 348 |
|
| 349 |
-
The header `<cerrno>`
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
intent is to remain in close alignment with the POSIX
|
| 353 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
|
| 355 |
## System error support <a id="syserr">[[syserr]]</a>
|
| 356 |
|
| 357 |
This subclause describes components that the standard library and
|
| 358 |
C++programs may use to report error conditions originating from the
|
|
@@ -360,10 +469,12 @@ operating system or other low-level application program interfaces.
|
|
| 360 |
|
| 361 |
Components described in this subclause shall not change the value of
|
| 362 |
`errno` ([[errno]]). Implementations should leave the error states
|
| 363 |
provided by other libraries unchanged.
|
| 364 |
|
|
|
|
|
|
|
| 365 |
``` cpp
|
| 366 |
namespace std {
|
| 367 |
class error_category;
|
| 368 |
const error_category& generic_category() noexcept;
|
| 369 |
const error_category& system_category() noexcept;
|
|
@@ -457,29 +568,45 @@ namespace std {
|
|
| 457 |
too_many_symbolic_link_levels, // ELOOP
|
| 458 |
value_too_large, // EOVERFLOW
|
| 459 |
wrong_protocol_type, // EPROTOTYPE
|
| 460 |
};
|
| 461 |
|
| 462 |
-
template <> struct is_error_condition_enum<errc> : true_type {
|
| 463 |
|
|
|
|
| 464 |
error_code make_error_code(errc e) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 465 |
error_condition make_error_condition(errc e) noexcept;
|
| 466 |
|
| 467 |
-
// [syserr.compare]
|
|
|
|
|
|
|
| 468 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 469 |
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 470 |
bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 471 |
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 472 |
bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
|
| 473 |
bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 474 |
bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 475 |
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 476 |
|
| 477 |
-
// [syserr.hash]
|
| 478 |
template <class T> struct hash;
|
| 479 |
template <> struct hash<error_code>;
|
| 480 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 481 |
```
|
| 482 |
|
| 483 |
The value of each `enum errc` constant shall be the same as the value of
|
| 484 |
the `<cerrno>` macro shown in the above synopsis. Whether or not the
|
| 485 |
`<system_error>` implementation exposes the `<cerrno>` macros is
|
|
@@ -496,14 +623,16 @@ conversions, respectively.
|
|
| 496 |
|
| 497 |
The class `error_category` serves as a base class for types used to
|
| 498 |
identify the source and encoding of a particular category of error code.
|
| 499 |
Classes may be derived from `error_category` to support categories of
|
| 500 |
errors in addition to those defined in this International Standard. Such
|
| 501 |
-
classes shall behave as specified in this subclause.
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
|
|
|
|
|
|
| 505 |
|
| 506 |
``` cpp
|
| 507 |
namespace std {
|
| 508 |
class error_category {
|
| 509 |
public:
|
|
@@ -522,12 +651,11 @@ namespace std {
|
|
| 522 |
bool operator<(const error_category& rhs) const noexcept;
|
| 523 |
};
|
| 524 |
|
| 525 |
const error_category& generic_category() noexcept;
|
| 526 |
const error_category& system_category() noexcept;
|
| 527 |
-
|
| 528 |
-
} // namespace std
|
| 529 |
```
|
| 530 |
|
| 531 |
#### Class `error_category` virtual members <a id="syserr.errcat.virtuals">[[syserr.errcat.virtuals]]</a>
|
| 532 |
|
| 533 |
``` cpp
|
|
@@ -590,11 +718,12 @@ bool operator!=(const error_category& rhs) const noexcept;
|
|
| 590 |
bool operator<(const error_category& rhs) const noexcept;
|
| 591 |
```
|
| 592 |
|
| 593 |
*Returns:* `less<const error_category*>()(this, &rhs)`.
|
| 594 |
|
| 595 |
-
`less` ([[comparisons]]) provides a total ordering for
|
|
|
|
| 596 |
|
| 597 |
#### Program defined classes derived from `error_category` <a id="syserr.errcat.derived">[[syserr.errcat.derived]]</a>
|
| 598 |
|
| 599 |
``` cpp
|
| 600 |
virtual const char* name() const noexcept = 0;
|
|
@@ -652,41 +781,45 @@ function shall return a pointer to the string `"system"`. The object’s
|
|
| 652 |
|
| 653 |
If the argument `ev` corresponds to a POSIX `errno` value `posv`, the
|
| 654 |
function shall return `error_condition(posv, generic_category())`.
|
| 655 |
Otherwise, the function shall return
|
| 656 |
`error_condition(ev, system_category())`. What constitutes
|
| 657 |
-
correspondence for any given operating system is unspecified.
|
| 658 |
-
|
| 659 |
-
|
| 660 |
-
|
|
|
|
|
|
|
| 661 |
|
| 662 |
### Class `error_code` <a id="syserr.errcode">[[syserr.errcode]]</a>
|
| 663 |
|
| 664 |
#### Class `error_code` overview <a id="syserr.errcode.overview">[[syserr.errcode.overview]]</a>
|
| 665 |
|
| 666 |
The class `error_code` describes an object used to hold error code
|
| 667 |
values, such as those originating from the operating system or other
|
| 668 |
-
low-level application program interfaces.
|
| 669 |
-
|
|
|
|
|
|
|
| 670 |
|
| 671 |
``` cpp
|
| 672 |
namespace std {
|
| 673 |
class error_code {
|
| 674 |
public:
|
| 675 |
-
// [syserr.errcode.constructors] constructors
|
| 676 |
error_code() noexcept;
|
| 677 |
error_code(int val, const error_category& cat) noexcept;
|
| 678 |
template <class ErrorCodeEnum>
|
| 679 |
error_code(ErrorCodeEnum e) noexcept;
|
| 680 |
|
| 681 |
-
// [syserr.errcode.modifiers] modifiers
|
| 682 |
void assign(int val, const error_category& cat) noexcept;
|
| 683 |
template <class ErrorCodeEnum>
|
| 684 |
error_code& operator=(ErrorCodeEnum e) noexcept;
|
| 685 |
void clear() noexcept;
|
| 686 |
|
| 687 |
-
// [syserr.errcode.observers] observers
|
| 688 |
int value() const noexcept;
|
| 689 |
const error_category& category() const noexcept;
|
| 690 |
error_condition default_error_condition() const noexcept;
|
| 691 |
string message() const;
|
| 692 |
explicit operator bool() const noexcept;
|
|
@@ -694,18 +827,17 @@ namespace std {
|
|
| 694 |
private:
|
| 695 |
int val_; // exposition only
|
| 696 |
const error_category* cat_; // exposition only
|
| 697 |
};
|
| 698 |
|
| 699 |
-
// [syserr.errcode.nonmembers] non-member functions
|
| 700 |
error_code make_error_code(errc e) noexcept;
|
| 701 |
-
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 702 |
|
| 703 |
template <class charT, class traits>
|
| 704 |
basic_ostream<charT, traits>&
|
| 705 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 706 |
-
}
|
| 707 |
```
|
| 708 |
|
| 709 |
#### Class `error_code` constructors <a id="syserr.errcode.constructors">[[syserr.errcode.constructors]]</a>
|
| 710 |
|
| 711 |
``` cpp
|
|
@@ -731,12 +863,14 @@ template <class ErrorCodeEnum>
|
|
| 731 |
|
| 732 |
*Effects:* Constructs an object of type `error_code`.
|
| 733 |
|
| 734 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 735 |
|
| 736 |
-
*Remarks:*
|
| 737 |
-
|
|
|
|
|
|
|
| 738 |
|
| 739 |
#### Class `error_code` modifiers <a id="syserr.errcode.modifiers">[[syserr.errcode.modifiers]]</a>
|
| 740 |
|
| 741 |
``` cpp
|
| 742 |
void assign(int val, const error_category& cat) noexcept;
|
|
@@ -751,12 +885,14 @@ template <class ErrorCodeEnum>
|
|
| 751 |
|
| 752 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 753 |
|
| 754 |
*Returns:* `*this`.
|
| 755 |
|
| 756 |
-
*Remarks:*
|
| 757 |
-
|
|
|
|
|
|
|
| 758 |
|
| 759 |
``` cpp
|
| 760 |
void clear() noexcept;
|
| 761 |
```
|
| 762 |
|
|
@@ -800,65 +936,56 @@ explicit operator bool() const noexcept;
|
|
| 800 |
error_code make_error_code(errc e) noexcept;
|
| 801 |
```
|
| 802 |
|
| 803 |
*Returns:* `error_code(static_cast<int>(e), generic_category())`.
|
| 804 |
|
| 805 |
-
``` cpp
|
| 806 |
-
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 807 |
-
```
|
| 808 |
-
|
| 809 |
-
*Returns:*
|
| 810 |
-
`lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value()`.
|
| 811 |
-
|
| 812 |
``` cpp
|
| 813 |
template <class charT, class traits>
|
| 814 |
basic_ostream<charT, traits>&
|
| 815 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 816 |
```
|
| 817 |
|
| 818 |
-
*Effects:*
|
| 819 |
-
`os <``<`` ec.category().name() <``<`` ’:’ <``<`` ec.value()`.
|
| 820 |
|
| 821 |
### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
|
| 822 |
|
| 823 |
#### Class `error_condition` overview <a id="syserr.errcondition.overview">[[syserr.errcondition.overview]]</a>
|
| 824 |
|
| 825 |
The class `error_condition` describes an object used to hold values
|
| 826 |
-
identifying error conditions.
|
| 827 |
-
|
| 828 |
-
|
|
|
|
|
|
|
| 829 |
|
| 830 |
``` cpp
|
| 831 |
namespace std {
|
| 832 |
class error_condition {
|
| 833 |
public:
|
| 834 |
-
// [syserr.errcondition.constructors] constructors
|
| 835 |
error_condition() noexcept;
|
| 836 |
error_condition(int val, const error_category& cat) noexcept;
|
| 837 |
template <class ErrorConditionEnum>
|
| 838 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 839 |
|
| 840 |
-
// [syserr.errcondition.modifiers] modifiers
|
| 841 |
void assign(int val, const error_category& cat) noexcept;
|
| 842 |
template <class ErrorConditionEnum>
|
| 843 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 844 |
void clear() noexcept;
|
| 845 |
|
| 846 |
-
// [syserr.errcondition.observers] observers
|
| 847 |
int value() const noexcept;
|
| 848 |
const error_category& category() const noexcept;
|
| 849 |
string message() const;
|
| 850 |
explicit operator bool() const noexcept;
|
| 851 |
|
| 852 |
private:
|
| 853 |
int val_; // exposition only
|
| 854 |
const error_category* cat_; // exposition only
|
| 855 |
};
|
| 856 |
-
|
| 857 |
-
// [syserr.errcondition.nonmembers] non-member functions:
|
| 858 |
-
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 859 |
-
} // namespace std
|
| 860 |
```
|
| 861 |
|
| 862 |
#### Class `error_condition` constructors <a id="syserr.errcondition.constructors">[[syserr.errcondition.constructors]]</a>
|
| 863 |
|
| 864 |
``` cpp
|
|
@@ -882,14 +1009,16 @@ template <class ErrorConditionEnum>
|
|
| 882 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 883 |
```
|
| 884 |
|
| 885 |
*Effects:* Constructs an object of type `error_condition`.
|
| 886 |
|
| 887 |
-
`*this == make_error_condition(e)`.
|
| 888 |
|
| 889 |
-
*Remarks:*
|
| 890 |
-
|
|
|
|
|
|
|
| 891 |
|
| 892 |
#### Class `error_condition` modifiers <a id="syserr.errcondition.modifiers">[[syserr.errcondition.modifiers]]</a>
|
| 893 |
|
| 894 |
``` cpp
|
| 895 |
void assign(int val, const error_category& cat) noexcept;
|
|
@@ -900,16 +1029,18 @@ void assign(int val, const error_category& cat) noexcept;
|
|
| 900 |
``` cpp
|
| 901 |
template <class ErrorConditionEnum>
|
| 902 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 903 |
```
|
| 904 |
|
| 905 |
-
`*this == make_error_condition(e)`.
|
| 906 |
|
| 907 |
*Returns:* `*this`.
|
| 908 |
|
| 909 |
-
*Remarks:*
|
| 910 |
-
|
|
|
|
|
|
|
| 911 |
|
| 912 |
``` cpp
|
| 913 |
void clear() noexcept;
|
| 914 |
```
|
| 915 |
|
|
@@ -947,20 +1078,31 @@ explicit operator bool() const noexcept;
|
|
| 947 |
error_condition make_error_condition(errc e) noexcept;
|
| 948 |
```
|
| 949 |
|
| 950 |
*Returns:* `error_condition(static_cast<int>(e), generic_category())`.
|
| 951 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 952 |
``` cpp
|
| 953 |
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 954 |
```
|
| 955 |
|
| 956 |
*Returns:*
|
| 957 |
`lhs.category() < rhs.category() || lhs.category() == rhs.category() &&`
|
| 958 |
`lhs.value() < rhs.value()`.
|
| 959 |
|
| 960 |
-
### Comparison operators <a id="syserr.compare">[[syserr.compare]]</a>
|
| 961 |
-
|
| 962 |
``` cpp
|
| 963 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 964 |
```
|
| 965 |
|
| 966 |
*Returns:*
|
|
@@ -998,44 +1140,42 @@ bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept
|
|
| 998 |
|
| 999 |
### System error hash support <a id="syserr.hash">[[syserr.hash]]</a>
|
| 1000 |
|
| 1001 |
``` cpp
|
| 1002 |
template <> struct hash<error_code>;
|
|
|
|
| 1003 |
```
|
| 1004 |
|
| 1005 |
-
The
|
| 1006 |
-
template `hash` ([[unord.hash]]).
|
| 1007 |
|
| 1008 |
### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
|
| 1009 |
|
| 1010 |
#### Class `system_error` overview <a id="syserr.syserr.overview">[[syserr.syserr.overview]]</a>
|
| 1011 |
|
| 1012 |
The class `system_error` describes an exception object used to report
|
| 1013 |
error conditions that have an associated error code. Such error
|
| 1014 |
conditions typically originate from the operating system or other
|
| 1015 |
low-level application program interfaces.
|
| 1016 |
|
| 1017 |
-
If an error represents an out-of-memory condition,
|
| 1018 |
-
encouraged to throw an exception object of type
|
| 1019 |
-
[[bad.alloc]] rather than `system_error`.
|
| 1020 |
|
| 1021 |
``` cpp
|
| 1022 |
namespace std {
|
| 1023 |
class system_error : public runtime_error {
|
| 1024 |
public:
|
| 1025 |
system_error(error_code ec, const string& what_arg);
|
| 1026 |
system_error(error_code ec, const char* what_arg);
|
| 1027 |
system_error(error_code ec);
|
| 1028 |
-
system_error(int ev, const error_category& ecat,
|
| 1029 |
-
|
| 1030 |
-
system_error(int ev, const error_category& ecat,
|
| 1031 |
-
const char* what_arg);
|
| 1032 |
system_error(int ev, const error_category& ecat);
|
| 1033 |
const error_code& code() const noexcept;
|
| 1034 |
-
const char* what() const noexcept;
|
| 1035 |
};
|
| 1036 |
-
}
|
| 1037 |
```
|
| 1038 |
|
| 1039 |
#### Class `system_error` members <a id="syserr.syserr.members">[[syserr.syserr.members]]</a>
|
| 1040 |
|
| 1041 |
``` cpp
|
|
@@ -1065,23 +1205,21 @@ system_error(error_code ec);
|
|
| 1065 |
*Effects:* Constructs an object of class `system_error`.
|
| 1066 |
|
| 1067 |
*Postconditions:* `code() == ec`.
|
| 1068 |
|
| 1069 |
``` cpp
|
| 1070 |
-
system_error(int ev, const error_category& ecat,
|
| 1071 |
-
const string& what_arg);
|
| 1072 |
```
|
| 1073 |
|
| 1074 |
*Effects:* Constructs an object of class `system_error`.
|
| 1075 |
|
| 1076 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
| 1077 |
|
| 1078 |
`string(what()).find(what_arg) != string::npos`.
|
| 1079 |
|
| 1080 |
``` cpp
|
| 1081 |
-
system_error(int ev, const error_category& ecat,
|
| 1082 |
-
const char* what_arg);
|
| 1083 |
```
|
| 1084 |
|
| 1085 |
*Effects:* Constructs an object of class `system_error`.
|
| 1086 |
|
| 1087 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
|
@@ -1102,23 +1240,28 @@ const error_code& code() const noexcept;
|
|
| 1102 |
|
| 1103 |
*Returns:* `ec` or `error_code(ev, ecat)`, from the constructor, as
|
| 1104 |
appropriate.
|
| 1105 |
|
| 1106 |
``` cpp
|
| 1107 |
-
const char* what() const noexcept;
|
| 1108 |
```
|
| 1109 |
|
| 1110 |
*Returns:* An NTBSincorporating the arguments supplied in the
|
| 1111 |
constructor.
|
| 1112 |
|
| 1113 |
-
The returned
|
| 1114 |
-
`what_arg + ": " + code.message()`.
|
| 1115 |
|
| 1116 |
<!-- Link reference definitions -->
|
| 1117 |
[assertions]: #assertions
|
|
|
|
| 1118 |
[bad.alloc]: language.md#bad.alloc
|
|
|
|
|
|
|
| 1119 |
[comparisons]: utilities.md#comparisons
|
|
|
|
|
|
|
| 1120 |
[diagnostics]: #diagnostics
|
| 1121 |
[diagnostics.general]: #diagnostics.general
|
| 1122 |
[domain.error]: #domain.error
|
| 1123 |
[errno]: #errno
|
| 1124 |
[invalid.argument]: #invalid.argument
|
|
@@ -1128,10 +1271,11 @@ The returned NTBS might be the contents of
|
|
| 1128 |
[overflow.error]: #overflow.error
|
| 1129 |
[range.error]: #range.error
|
| 1130 |
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 1131 |
[runtime.error]: #runtime.error
|
| 1132 |
[std.exceptions]: #std.exceptions
|
|
|
|
| 1133 |
[syserr]: #syserr
|
| 1134 |
[syserr.compare]: #syserr.compare
|
| 1135 |
[syserr.errcat]: #syserr.errcat
|
| 1136 |
[syserr.errcat.derived]: #syserr.errcat.derived
|
| 1137 |
[syserr.errcat.nonvirtuals]: #syserr.errcat.nonvirtuals
|
|
@@ -1152,10 +1296,9 @@ The returned NTBS might be the contents of
|
|
| 1152 |
[syserr.errcondition.overview]: #syserr.errcondition.overview
|
| 1153 |
[syserr.hash]: #syserr.hash
|
| 1154 |
[syserr.syserr]: #syserr.syserr
|
| 1155 |
[syserr.syserr.members]: #syserr.syserr.members
|
| 1156 |
[syserr.syserr.overview]: #syserr.syserr.overview
|
| 1157 |
-
[
|
| 1158 |
-
[tab:diagnostics.hdr.cerrno]: #tab:diagnostics.hdr.cerrno
|
| 1159 |
[tab:diagnostics.lib.summary]: #tab:diagnostics.lib.summary
|
| 1160 |
[underflow.error]: #underflow.error
|
| 1161 |
[unord.hash]: utilities.md#unord.hash
|
|
|
|
| 20 |
| [[syserr]] | System error support | `<system_error>` |
|
| 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
|
| 27 |
model 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
|
|
|
|
| 35 |
program. They cannot be easily predicted in advance. The header
|
| 36 |
`<stdexcept>` defines several types of predefined exceptions for
|
| 37 |
reporting errors in a C++program. These exceptions are related by
|
| 38 |
inheritance.
|
| 39 |
|
| 40 |
+
### Header `<stdexcept>` synopsis <a id="stdexcept.syn">[[stdexcept.syn]]</a>
|
| 41 |
+
|
| 42 |
``` cpp
|
| 43 |
namespace std {
|
| 44 |
class logic_error;
|
| 45 |
class domain_error;
|
| 46 |
class invalid_argument;
|
|
|
|
| 73 |
logic_error(const string& what_arg);
|
| 74 |
```
|
| 75 |
|
| 76 |
*Effects:* Constructs an object of class `logic_error`.
|
| 77 |
|
| 78 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 79 |
|
| 80 |
``` cpp
|
| 81 |
logic_error(const char* what_arg);
|
| 82 |
```
|
| 83 |
|
| 84 |
*Effects:* Constructs an object of class `logic_error`.
|
| 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 {
|
|
|
|
| 104 |
domain_error(const string& what_arg);
|
| 105 |
```
|
| 106 |
|
| 107 |
*Effects:* Constructs an object of class `domain_error`.
|
| 108 |
|
| 109 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 110 |
|
| 111 |
``` cpp
|
| 112 |
domain_error(const char* what_arg);
|
| 113 |
```
|
| 114 |
|
| 115 |
*Effects:* Constructs an object of class `domain_error`.
|
| 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 {
|
|
|
|
| 135 |
invalid_argument(const string& what_arg);
|
| 136 |
```
|
| 137 |
|
| 138 |
*Effects:* Constructs an object of class `invalid_argument`.
|
| 139 |
|
| 140 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 141 |
|
| 142 |
``` cpp
|
| 143 |
invalid_argument(const char* what_arg);
|
| 144 |
```
|
| 145 |
|
| 146 |
*Effects:* Constructs an object of class `invalid_argument`.
|
| 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 {
|
|
|
|
| 167 |
length_error(const string& what_arg);
|
| 168 |
```
|
| 169 |
|
| 170 |
*Effects:* Constructs an object of class `length_error`.
|
| 171 |
|
| 172 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 173 |
|
| 174 |
``` cpp
|
| 175 |
length_error(const char* what_arg);
|
| 176 |
```
|
| 177 |
|
| 178 |
*Effects:* Constructs an object of class `length_error`.
|
| 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 {
|
|
|
|
| 198 |
out_of_range(const string& what_arg);
|
| 199 |
```
|
| 200 |
|
| 201 |
*Effects:* Constructs an object of class `out_of_range`.
|
| 202 |
|
| 203 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 204 |
|
| 205 |
``` cpp
|
| 206 |
out_of_range(const char* what_arg);
|
| 207 |
```
|
| 208 |
|
| 209 |
*Effects:* Constructs an object of class `out_of_range`.
|
| 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 {
|
|
|
|
| 230 |
runtime_error(const string& what_arg);
|
| 231 |
```
|
| 232 |
|
| 233 |
*Effects:* Constructs an object of class `runtime_error`.
|
| 234 |
|
| 235 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 236 |
|
| 237 |
``` cpp
|
| 238 |
runtime_error(const char* what_arg);
|
| 239 |
```
|
| 240 |
|
| 241 |
*Effects:* Constructs an object of class `runtime_error`.
|
| 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 {
|
|
|
|
| 261 |
range_error(const string& what_arg);
|
| 262 |
```
|
| 263 |
|
| 264 |
*Effects:* Constructs an object of class `range_error`.
|
| 265 |
|
| 266 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 267 |
|
| 268 |
``` cpp
|
| 269 |
range_error(const char* what_arg);
|
| 270 |
```
|
| 271 |
|
| 272 |
*Effects:* Constructs an object of class `range_error`.
|
| 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 {
|
|
|
|
| 292 |
overflow_error(const string& what_arg);
|
| 293 |
```
|
| 294 |
|
| 295 |
*Effects:* Constructs an object of class `overflow_error`.
|
| 296 |
|
| 297 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 298 |
|
| 299 |
``` cpp
|
| 300 |
overflow_error(const char* what_arg);
|
| 301 |
```
|
| 302 |
|
| 303 |
*Effects:* Constructs an object of class `overflow_error`.
|
| 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 {
|
|
|
|
| 323 |
underflow_error(const string& what_arg);
|
| 324 |
```
|
| 325 |
|
| 326 |
*Effects:* Constructs an object of class `underflow_error`.
|
| 327 |
|
| 328 |
+
*Postconditions:* `strcmp(what(), what_arg.c_str()) == 0`.
|
| 329 |
|
| 330 |
``` cpp
|
| 331 |
underflow_error(const char* what_arg);
|
| 332 |
```
|
| 333 |
|
| 334 |
*Effects:* Constructs an object of class `underflow_error`.
|
| 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.
|
|
|
|
|
|
|
| 342 |
|
| 343 |
+
### Header `<cassert>` synopsis <a id="cassert.syn">[[cassert.syn]]</a>
|
| 344 |
|
| 345 |
+
``` cpp
|
| 346 |
+
#define assert(E) see below
|
| 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 7.2.
|
| 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]]), if
|
| 358 |
+
|
| 359 |
+
- `NDEBUG` is defined at the point where `assert` is last defined or
|
| 360 |
+
redefined, or
|
| 361 |
+
- `E` contextually converted to `bool` (Clause [[conv]]) is a constant
|
| 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
|
| 367 |
+
`<errno.h>`, except that `errno` shall be defined as a macro.
|
| 368 |
+
|
| 369 |
+
[*Note 1*: The intent is to remain in close alignment with the POSIX
|
| 370 |
+
standard. — *end note*]
|
| 371 |
+
|
| 372 |
+
A separate `errno` value shall be provided for each thread.
|
| 373 |
+
|
| 374 |
+
### Header `<cerrno>` synopsis <a id="cerrno.syn">[[cerrno.syn]]</a>
|
| 375 |
+
|
| 376 |
+
``` cpp
|
| 377 |
+
#define errno see below
|
| 378 |
+
|
| 379 |
+
#define E2BIG see below
|
| 380 |
+
#define EACCES see below
|
| 381 |
+
#define EADDRINUSE see below
|
| 382 |
+
#define EADDRNOTAVAIL see below
|
| 383 |
+
#define EAFNOSUPPORT see below
|
| 384 |
+
#define EAGAIN see below
|
| 385 |
+
#define EALREADY see below
|
| 386 |
+
#define EBADF see below
|
| 387 |
+
#define EBADMSG see below
|
| 388 |
+
#define EBUSY see below
|
| 389 |
+
#define ECANCELED see below
|
| 390 |
+
#define ECHILD see below
|
| 391 |
+
#define ECONNABORTED see below
|
| 392 |
+
#define ECONNREFUSED see below
|
| 393 |
+
#define ECONNRESET see below
|
| 394 |
+
#define EDEADLK see below
|
| 395 |
+
#define EDESTADDRREQ see below
|
| 396 |
+
#define EDOM see below
|
| 397 |
+
#define EEXIST see below
|
| 398 |
+
#define EFAULT see below
|
| 399 |
+
#define EFBIG see below
|
| 400 |
+
#define EHOSTUNREACH see below
|
| 401 |
+
#define EIDRM see below
|
| 402 |
+
#define EILSEQ see below
|
| 403 |
+
#define EINPROGRESS see below
|
| 404 |
+
#define EINTR see below
|
| 405 |
+
#define EINVAL see below
|
| 406 |
+
#define EIO see below
|
| 407 |
+
#define EISCONN see below
|
| 408 |
+
#define EISDIR see below
|
| 409 |
+
#define ELOOP see below
|
| 410 |
+
#define EMFILE see below
|
| 411 |
+
#define EMLINK see below
|
| 412 |
+
#define EMSGSIZE see below
|
| 413 |
+
#define ENAMETOOLONG see below
|
| 414 |
+
#define ENETDOWN see below
|
| 415 |
+
#define ENETRESET see below
|
| 416 |
+
#define ENETUNREACH see below
|
| 417 |
+
#define ENFILE see below
|
| 418 |
+
#define ENOBUFS see below
|
| 419 |
+
#define ENODATA see below
|
| 420 |
+
#define ENODEV see below
|
| 421 |
+
#define ENOENT see below
|
| 422 |
+
#define ENOEXEC see below
|
| 423 |
+
#define ENOLCK see below
|
| 424 |
+
#define ENOLINK see below
|
| 425 |
+
#define ENOMEM see below
|
| 426 |
+
#define ENOMSG see below
|
| 427 |
+
#define ENOPROTOOPT see below
|
| 428 |
+
#define ENOSPC see below
|
| 429 |
+
#define ENOSR see below
|
| 430 |
+
#define ENOSTR see below
|
| 431 |
+
#define ENOSYS see below
|
| 432 |
+
#define ENOTCONN see below
|
| 433 |
+
#define ENOTDIR see below
|
| 434 |
+
#define ENOTEMPTY see below
|
| 435 |
+
#define ENOTRECOVERABLE see below
|
| 436 |
+
#define ENOTSOCK see below
|
| 437 |
+
#define ENOTSUP see below
|
| 438 |
+
#define ENOTTY see below
|
| 439 |
+
#define ENXIO see below
|
| 440 |
+
#define EOPNOTSUPP see below
|
| 441 |
+
#define EOVERFLOW see below
|
| 442 |
+
#define EOWNERDEAD see below
|
| 443 |
+
#define EPERM see below
|
| 444 |
+
#define EPIPE see below
|
| 445 |
+
#define EPROTO see below
|
| 446 |
+
#define EPROTONOSUPPORT see below
|
| 447 |
+
#define EPROTOTYPE see below
|
| 448 |
+
#define ERANGE see below
|
| 449 |
+
#define EROFS see below
|
| 450 |
+
#define ESPIPE see below
|
| 451 |
+
#define ESRCH see below
|
| 452 |
+
#define ETIME see below
|
| 453 |
+
#define ETIMEDOUT see below
|
| 454 |
+
#define ETXTBSY see below
|
| 455 |
+
#define EWOULDBLOCK see below
|
| 456 |
+
#define EXDEV see below
|
| 457 |
+
```
|
| 458 |
+
|
| 459 |
+
The meaning of the macros in this header is defined by the POSIX
|
| 460 |
+
standard.
|
| 461 |
+
|
| 462 |
+
ISO C 7.5.
|
| 463 |
|
| 464 |
## System error support <a id="syserr">[[syserr]]</a>
|
| 465 |
|
| 466 |
This subclause describes components that the standard library and
|
| 467 |
C++programs may use to report error conditions originating from the
|
|
|
|
| 469 |
|
| 470 |
Components described in this subclause shall not change the value of
|
| 471 |
`errno` ([[errno]]). Implementations should leave the error states
|
| 472 |
provided by other libraries unchanged.
|
| 473 |
|
| 474 |
+
### Header `<system_error>` synopsis <a id="system_error.syn">[[system_error.syn]]</a>
|
| 475 |
+
|
| 476 |
``` cpp
|
| 477 |
namespace std {
|
| 478 |
class error_category;
|
| 479 |
const error_category& generic_category() noexcept;
|
| 480 |
const error_category& system_category() noexcept;
|
|
|
|
| 568 |
too_many_symbolic_link_levels, // ELOOP
|
| 569 |
value_too_large, // EOVERFLOW
|
| 570 |
wrong_protocol_type, // EPROTOTYPE
|
| 571 |
};
|
| 572 |
|
| 573 |
+
template <> struct is_error_condition_enum<errc> : true_type {};
|
| 574 |
|
| 575 |
+
// [syserr.errcode.nonmembers], non-member functions
|
| 576 |
error_code make_error_code(errc e) noexcept;
|
| 577 |
+
|
| 578 |
+
template <class charT, class traits>
|
| 579 |
+
basic_ostream<charT, traits>&
|
| 580 |
+
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 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 |
bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
|
| 593 |
bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 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 <class T> inline constexpr bool is_error_code_enum_v
|
| 604 |
+
= is_error_code_enum<T>::value;
|
| 605 |
+
template <class T> inline constexpr bool is_error_condition_enum_v
|
| 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
|
|
|
|
| 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 International Standard. Such
|
| 628 |
+
classes shall behave as specified in this subclause.
|
| 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*]
|
| 634 |
|
| 635 |
``` cpp
|
| 636 |
namespace std {
|
| 637 |
class error_category {
|
| 638 |
public:
|
|
|
|
| 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 |
#### Class `error_category` virtual members <a id="syserr.errcat.virtuals">[[syserr.errcat.virtuals]]</a>
|
| 660 |
|
| 661 |
``` cpp
|
|
|
|
| 718 |
bool operator<(const error_category& rhs) const noexcept;
|
| 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 defined classes derived from `error_category` <a id="syserr.errcat.derived">[[syserr.errcat.derived]]</a>
|
| 727 |
|
| 728 |
``` cpp
|
| 729 |
virtual const char* name() const noexcept = 0;
|
|
|
|
| 781 |
|
| 782 |
If the argument `ev` corresponds to a POSIX `errno` value `posv`, the
|
| 783 |
function shall return `error_condition(posv, generic_category())`.
|
| 784 |
Otherwise, the function shall return
|
| 785 |
`error_condition(ev, system_category())`. What constitutes
|
| 786 |
+
correspondence for any given operating system is unspecified.
|
| 787 |
+
|
| 788 |
+
[*Note 1*: The number of potential system error codes is large and
|
| 789 |
+
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 |
#### Class `error_code` overview <a id="syserr.errcode.overview">[[syserr.errcode.overview]]</a>
|
| 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 |
+
|
| 801 |
+
[*Note 1*: Class `error_code` is an adjunct to error reporting by
|
| 802 |
+
exception. — *end note*]
|
| 803 |
|
| 804 |
``` cpp
|
| 805 |
namespace std {
|
| 806 |
class error_code {
|
| 807 |
public:
|
| 808 |
+
// [syserr.errcode.constructors], constructors
|
| 809 |
error_code() noexcept;
|
| 810 |
error_code(int val, const error_category& cat) noexcept;
|
| 811 |
template <class ErrorCodeEnum>
|
| 812 |
error_code(ErrorCodeEnum e) noexcept;
|
| 813 |
|
| 814 |
+
// [syserr.errcode.modifiers], modifiers
|
| 815 |
void assign(int val, const error_category& cat) noexcept;
|
| 816 |
template <class ErrorCodeEnum>
|
| 817 |
error_code& operator=(ErrorCodeEnum e) noexcept;
|
| 818 |
void clear() noexcept;
|
| 819 |
|
| 820 |
+
// [syserr.errcode.observers], observers
|
| 821 |
int value() const noexcept;
|
| 822 |
const error_category& category() const noexcept;
|
| 823 |
error_condition default_error_condition() const noexcept;
|
| 824 |
string message() const;
|
| 825 |
explicit operator bool() const noexcept;
|
|
|
|
| 827 |
private:
|
| 828 |
int val_; // exposition only
|
| 829 |
const error_category* cat_; // exposition only
|
| 830 |
};
|
| 831 |
|
| 832 |
+
// [syserr.errcode.nonmembers], non-member functions
|
| 833 |
error_code make_error_code(errc e) noexcept;
|
|
|
|
| 834 |
|
| 835 |
template <class charT, class traits>
|
| 836 |
basic_ostream<charT, traits>&
|
| 837 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 838 |
+
}
|
| 839 |
```
|
| 840 |
|
| 841 |
#### Class `error_code` constructors <a id="syserr.errcode.constructors">[[syserr.errcode.constructors]]</a>
|
| 842 |
|
| 843 |
``` cpp
|
|
|
|
| 863 |
|
| 864 |
*Effects:* Constructs an object of type `error_code`.
|
| 865 |
|
| 866 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 867 |
|
| 868 |
+
*Remarks:*
|
| 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;
|
|
|
|
| 885 |
|
| 886 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 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 |
|
|
|
|
| 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:* As if by: `os << ec.category().name() << ’:’ << ec.value();`
|
|
|
|
| 948 |
|
| 949 |
### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
|
| 950 |
|
| 951 |
#### Class `error_condition` overview <a id="syserr.errcondition.overview">[[syserr.errcondition.overview]]</a>
|
| 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 ([[syserr.errcode]]) are implementation
|
| 958 |
+
specific. — *end note*]
|
| 959 |
|
| 960 |
``` cpp
|
| 961 |
namespace std {
|
| 962 |
class error_condition {
|
| 963 |
public:
|
| 964 |
+
// [syserr.errcondition.constructors], constructors
|
| 965 |
error_condition() noexcept;
|
| 966 |
error_condition(int val, const error_category& cat) noexcept;
|
| 967 |
template <class ErrorConditionEnum>
|
| 968 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 969 |
|
| 970 |
+
// [syserr.errcondition.modifiers], modifiers
|
| 971 |
void assign(int val, const error_category& cat) noexcept;
|
| 972 |
template <class ErrorConditionEnum>
|
| 973 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 974 |
void clear() noexcept;
|
| 975 |
|
| 976 |
+
// [syserr.errcondition.observers], observers
|
| 977 |
int value() const noexcept;
|
| 978 |
const error_category& category() const noexcept;
|
| 979 |
string message() const;
|
| 980 |
explicit operator bool() const noexcept;
|
| 981 |
|
| 982 |
private:
|
| 983 |
int val_; // exposition only
|
| 984 |
const error_category* cat_; // exposition only
|
| 985 |
};
|
| 986 |
+
}
|
|
|
|
|
|
|
|
|
|
| 987 |
```
|
| 988 |
|
| 989 |
#### Class `error_condition` constructors <a id="syserr.errcondition.constructors">[[syserr.errcondition.constructors]]</a>
|
| 990 |
|
| 991 |
``` cpp
|
|
|
|
| 1009 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 1010 |
```
|
| 1011 |
|
| 1012 |
*Effects:* Constructs an object of type `error_condition`.
|
| 1013 |
|
| 1014 |
+
*Postconditions:* `*this == make_error_condition(e)`.
|
| 1015 |
|
| 1016 |
+
*Remarks:*
|
| 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;
|
|
|
|
| 1029 |
``` cpp
|
| 1030 |
template <class ErrorConditionEnum>
|
| 1031 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 1032 |
```
|
| 1033 |
|
| 1034 |
+
*Postconditions:* `*this == make_error_condition(e)`.
|
| 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 |
|
|
|
|
| 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:*
|
|
|
|
| 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 ([[unord.hash]]).
|
|
|
|
| 1149 |
|
| 1150 |
### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
|
| 1151 |
|
| 1152 |
#### Class `system_error` overview <a id="syserr.syserr.overview">[[syserr.syserr.overview]]</a>
|
| 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` ([[bad.alloc]]) rather than `system_error`. — *end note*]
|
| 1162 |
|
| 1163 |
``` cpp
|
| 1164 |
namespace std {
|
| 1165 |
class system_error : public runtime_error {
|
| 1166 |
public:
|
| 1167 |
system_error(error_code ec, const string& what_arg);
|
| 1168 |
system_error(error_code ec, const char* what_arg);
|
| 1169 |
system_error(error_code ec);
|
| 1170 |
+
system_error(int ev, const error_category& ecat, const string& what_arg);
|
| 1171 |
+
system_error(int ev, const error_category& ecat, const char* what_arg);
|
|
|
|
|
|
|
| 1172 |
system_error(int ev, const error_category& ecat);
|
| 1173 |
const error_code& code() const noexcept;
|
| 1174 |
+
const char* what() const noexcept override;
|
| 1175 |
};
|
| 1176 |
+
}
|
| 1177 |
```
|
| 1178 |
|
| 1179 |
#### Class `system_error` members <a id="syserr.syserr.members">[[syserr.syserr.members]]</a>
|
| 1180 |
|
| 1181 |
``` cpp
|
|
|
|
| 1205 |
*Effects:* Constructs an object of class `system_error`.
|
| 1206 |
|
| 1207 |
*Postconditions:* `code() == ec`.
|
| 1208 |
|
| 1209 |
``` cpp
|
| 1210 |
+
system_error(int ev, const error_category& ecat, const string& what_arg);
|
|
|
|
| 1211 |
```
|
| 1212 |
|
| 1213 |
*Effects:* Constructs an object of class `system_error`.
|
| 1214 |
|
| 1215 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
| 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 |
*Effects:* Constructs an object of class `system_error`.
|
| 1224 |
|
| 1225 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
|
|
|
| 1240 |
|
| 1241 |
*Returns:* `ec` or `error_code(ev, ecat)`, from the constructor, as
|
| 1242 |
appropriate.
|
| 1243 |
|
| 1244 |
``` cpp
|
| 1245 |
+
const char* what() const noexcept override;
|
| 1246 |
```
|
| 1247 |
|
| 1248 |
*Returns:* An NTBSincorporating the arguments supplied in the
|
| 1249 |
constructor.
|
| 1250 |
|
| 1251 |
+
[*Note 1*: The returned NTBSmight be the contents of
|
| 1252 |
+
`what_arg + ": " + code.message()`. — *end note*]
|
| 1253 |
|
| 1254 |
<!-- Link reference definitions -->
|
| 1255 |
[assertions]: #assertions
|
| 1256 |
+
[assertions.assert]: #assertions.assert
|
| 1257 |
[bad.alloc]: language.md#bad.alloc
|
| 1258 |
+
[cassert.syn]: #cassert.syn
|
| 1259 |
+
[cerrno.syn]: #cerrno.syn
|
| 1260 |
[comparisons]: utilities.md#comparisons
|
| 1261 |
+
[conv]: conv.md#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
|
|
|
|
| 1271 |
[overflow.error]: #overflow.error
|
| 1272 |
[range.error]: #range.error
|
| 1273 |
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 1274 |
[runtime.error]: #runtime.error
|
| 1275 |
[std.exceptions]: #std.exceptions
|
| 1276 |
+
[stdexcept.syn]: #stdexcept.syn
|
| 1277 |
[syserr]: #syserr
|
| 1278 |
[syserr.compare]: #syserr.compare
|
| 1279 |
[syserr.errcat]: #syserr.errcat
|
| 1280 |
[syserr.errcat.derived]: #syserr.errcat.derived
|
| 1281 |
[syserr.errcat.nonvirtuals]: #syserr.errcat.nonvirtuals
|
|
|
|
| 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 |
+
[system_error.syn]: #system_error.syn
|
|
|
|
| 1302 |
[tab:diagnostics.lib.summary]: #tab:diagnostics.lib.summary
|
| 1303 |
[underflow.error]: #underflow.error
|
| 1304 |
[unord.hash]: utilities.md#unord.hash
|