- tmp/tmphdlq1l5h/{from.md → to.md} +108 -74
tmp/tmphdlq1l5h/{from.md → to.md}
RENAMED
|
@@ -6,10 +6,12 @@ operating system or other low-level application program interfaces.
|
|
| 6 |
|
| 7 |
Components described in this subclause shall not change the value of
|
| 8 |
`errno` ([[errno]]). Implementations should leave the error states
|
| 9 |
provided by other libraries unchanged.
|
| 10 |
|
|
|
|
|
|
|
| 11 |
``` cpp
|
| 12 |
namespace std {
|
| 13 |
class error_category;
|
| 14 |
const error_category& generic_category() noexcept;
|
| 15 |
const error_category& system_category() noexcept;
|
|
@@ -103,29 +105,45 @@ namespace std {
|
|
| 103 |
too_many_symbolic_link_levels, // ELOOP
|
| 104 |
value_too_large, // EOVERFLOW
|
| 105 |
wrong_protocol_type, // EPROTOTYPE
|
| 106 |
};
|
| 107 |
|
| 108 |
-
template <> struct is_error_condition_enum<errc> : true_type {
|
| 109 |
|
|
|
|
| 110 |
error_code make_error_code(errc e) noexcept;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
error_condition make_error_condition(errc e) noexcept;
|
| 112 |
|
| 113 |
-
// [syserr.compare]
|
|
|
|
|
|
|
| 114 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 115 |
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 116 |
bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 117 |
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 118 |
bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
|
| 119 |
bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 120 |
bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 121 |
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 122 |
|
| 123 |
-
// [syserr.hash]
|
| 124 |
template <class T> struct hash;
|
| 125 |
template <> struct hash<error_code>;
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
```
|
| 128 |
|
| 129 |
The value of each `enum errc` constant shall be the same as the value of
|
| 130 |
the `<cerrno>` macro shown in the above synopsis. Whether or not the
|
| 131 |
`<system_error>` implementation exposes the `<cerrno>` macros is
|
|
@@ -142,14 +160,16 @@ conversions, respectively.
|
|
| 142 |
|
| 143 |
The class `error_category` serves as a base class for types used to
|
| 144 |
identify the source and encoding of a particular category of error code.
|
| 145 |
Classes may be derived from `error_category` to support categories of
|
| 146 |
errors in addition to those defined in this International Standard. Such
|
| 147 |
-
classes shall behave as specified in this subclause.
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
|
|
|
|
|
|
| 151 |
|
| 152 |
``` cpp
|
| 153 |
namespace std {
|
| 154 |
class error_category {
|
| 155 |
public:
|
|
@@ -168,12 +188,11 @@ namespace std {
|
|
| 168 |
bool operator<(const error_category& rhs) const noexcept;
|
| 169 |
};
|
| 170 |
|
| 171 |
const error_category& generic_category() noexcept;
|
| 172 |
const error_category& system_category() noexcept;
|
| 173 |
-
|
| 174 |
-
} // namespace std
|
| 175 |
```
|
| 176 |
|
| 177 |
#### Class `error_category` virtual members <a id="syserr.errcat.virtuals">[[syserr.errcat.virtuals]]</a>
|
| 178 |
|
| 179 |
``` cpp
|
|
@@ -236,11 +255,12 @@ bool operator!=(const error_category& rhs) const noexcept;
|
|
| 236 |
bool operator<(const error_category& rhs) const noexcept;
|
| 237 |
```
|
| 238 |
|
| 239 |
*Returns:* `less<const error_category*>()(this, &rhs)`.
|
| 240 |
|
| 241 |
-
`less` ([[comparisons]]) provides a total ordering for
|
|
|
|
| 242 |
|
| 243 |
#### Program defined classes derived from `error_category` <a id="syserr.errcat.derived">[[syserr.errcat.derived]]</a>
|
| 244 |
|
| 245 |
``` cpp
|
| 246 |
virtual const char* name() const noexcept = 0;
|
|
@@ -298,41 +318,45 @@ function shall return a pointer to the string `"system"`. The object’s
|
|
| 298 |
|
| 299 |
If the argument `ev` corresponds to a POSIX `errno` value `posv`, the
|
| 300 |
function shall return `error_condition(posv, generic_category())`.
|
| 301 |
Otherwise, the function shall return
|
| 302 |
`error_condition(ev, system_category())`. What constitutes
|
| 303 |
-
correspondence for any given operating system is unspecified.
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
|
|
|
|
|
|
| 307 |
|
| 308 |
### Class `error_code` <a id="syserr.errcode">[[syserr.errcode]]</a>
|
| 309 |
|
| 310 |
#### Class `error_code` overview <a id="syserr.errcode.overview">[[syserr.errcode.overview]]</a>
|
| 311 |
|
| 312 |
The class `error_code` describes an object used to hold error code
|
| 313 |
values, such as those originating from the operating system or other
|
| 314 |
-
low-level application program interfaces.
|
| 315 |
-
|
|
|
|
|
|
|
| 316 |
|
| 317 |
``` cpp
|
| 318 |
namespace std {
|
| 319 |
class error_code {
|
| 320 |
public:
|
| 321 |
-
// [syserr.errcode.constructors] constructors
|
| 322 |
error_code() noexcept;
|
| 323 |
error_code(int val, const error_category& cat) noexcept;
|
| 324 |
template <class ErrorCodeEnum>
|
| 325 |
error_code(ErrorCodeEnum e) noexcept;
|
| 326 |
|
| 327 |
-
// [syserr.errcode.modifiers] modifiers
|
| 328 |
void assign(int val, const error_category& cat) noexcept;
|
| 329 |
template <class ErrorCodeEnum>
|
| 330 |
error_code& operator=(ErrorCodeEnum e) noexcept;
|
| 331 |
void clear() noexcept;
|
| 332 |
|
| 333 |
-
// [syserr.errcode.observers] observers
|
| 334 |
int value() const noexcept;
|
| 335 |
const error_category& category() const noexcept;
|
| 336 |
error_condition default_error_condition() const noexcept;
|
| 337 |
string message() const;
|
| 338 |
explicit operator bool() const noexcept;
|
|
@@ -340,18 +364,17 @@ namespace std {
|
|
| 340 |
private:
|
| 341 |
int val_; // exposition only
|
| 342 |
const error_category* cat_; // exposition only
|
| 343 |
};
|
| 344 |
|
| 345 |
-
// [syserr.errcode.nonmembers] non-member functions
|
| 346 |
error_code make_error_code(errc e) noexcept;
|
| 347 |
-
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 348 |
|
| 349 |
template <class charT, class traits>
|
| 350 |
basic_ostream<charT, traits>&
|
| 351 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 352 |
-
}
|
| 353 |
```
|
| 354 |
|
| 355 |
#### Class `error_code` constructors <a id="syserr.errcode.constructors">[[syserr.errcode.constructors]]</a>
|
| 356 |
|
| 357 |
``` cpp
|
|
@@ -377,12 +400,14 @@ template <class ErrorCodeEnum>
|
|
| 377 |
|
| 378 |
*Effects:* Constructs an object of type `error_code`.
|
| 379 |
|
| 380 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 381 |
|
| 382 |
-
*Remarks:*
|
| 383 |
-
|
|
|
|
|
|
|
| 384 |
|
| 385 |
#### Class `error_code` modifiers <a id="syserr.errcode.modifiers">[[syserr.errcode.modifiers]]</a>
|
| 386 |
|
| 387 |
``` cpp
|
| 388 |
void assign(int val, const error_category& cat) noexcept;
|
|
@@ -397,12 +422,14 @@ template <class ErrorCodeEnum>
|
|
| 397 |
|
| 398 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 399 |
|
| 400 |
*Returns:* `*this`.
|
| 401 |
|
| 402 |
-
*Remarks:*
|
| 403 |
-
|
|
|
|
|
|
|
| 404 |
|
| 405 |
``` cpp
|
| 406 |
void clear() noexcept;
|
| 407 |
```
|
| 408 |
|
|
@@ -446,65 +473,56 @@ explicit operator bool() const noexcept;
|
|
| 446 |
error_code make_error_code(errc e) noexcept;
|
| 447 |
```
|
| 448 |
|
| 449 |
*Returns:* `error_code(static_cast<int>(e), generic_category())`.
|
| 450 |
|
| 451 |
-
``` cpp
|
| 452 |
-
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 453 |
-
```
|
| 454 |
-
|
| 455 |
-
*Returns:*
|
| 456 |
-
`lhs.category() < rhs.category() || lhs.category() == rhs.category() && lhs.value() < rhs.value()`.
|
| 457 |
-
|
| 458 |
``` cpp
|
| 459 |
template <class charT, class traits>
|
| 460 |
basic_ostream<charT, traits>&
|
| 461 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 462 |
```
|
| 463 |
|
| 464 |
-
*Effects:*
|
| 465 |
-
`os <``<`` ec.category().name() <``<`` ’:’ <``<`` ec.value()`.
|
| 466 |
|
| 467 |
### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
|
| 468 |
|
| 469 |
#### Class `error_condition` overview <a id="syserr.errcondition.overview">[[syserr.errcondition.overview]]</a>
|
| 470 |
|
| 471 |
The class `error_condition` describes an object used to hold values
|
| 472 |
-
identifying error conditions.
|
| 473 |
-
|
| 474 |
-
|
|
|
|
|
|
|
| 475 |
|
| 476 |
``` cpp
|
| 477 |
namespace std {
|
| 478 |
class error_condition {
|
| 479 |
public:
|
| 480 |
-
// [syserr.errcondition.constructors] constructors
|
| 481 |
error_condition() noexcept;
|
| 482 |
error_condition(int val, const error_category& cat) noexcept;
|
| 483 |
template <class ErrorConditionEnum>
|
| 484 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 485 |
|
| 486 |
-
// [syserr.errcondition.modifiers] modifiers
|
| 487 |
void assign(int val, const error_category& cat) noexcept;
|
| 488 |
template <class ErrorConditionEnum>
|
| 489 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 490 |
void clear() noexcept;
|
| 491 |
|
| 492 |
-
// [syserr.errcondition.observers] observers
|
| 493 |
int value() const noexcept;
|
| 494 |
const error_category& category() const noexcept;
|
| 495 |
string message() const;
|
| 496 |
explicit operator bool() const noexcept;
|
| 497 |
|
| 498 |
private:
|
| 499 |
int val_; // exposition only
|
| 500 |
const error_category* cat_; // exposition only
|
| 501 |
};
|
| 502 |
-
|
| 503 |
-
// [syserr.errcondition.nonmembers] non-member functions:
|
| 504 |
-
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 505 |
-
} // namespace std
|
| 506 |
```
|
| 507 |
|
| 508 |
#### Class `error_condition` constructors <a id="syserr.errcondition.constructors">[[syserr.errcondition.constructors]]</a>
|
| 509 |
|
| 510 |
``` cpp
|
|
@@ -528,14 +546,16 @@ template <class ErrorConditionEnum>
|
|
| 528 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 529 |
```
|
| 530 |
|
| 531 |
*Effects:* Constructs an object of type `error_condition`.
|
| 532 |
|
| 533 |
-
`*this == make_error_condition(e)`.
|
| 534 |
|
| 535 |
-
*Remarks:*
|
| 536 |
-
|
|
|
|
|
|
|
| 537 |
|
| 538 |
#### Class `error_condition` modifiers <a id="syserr.errcondition.modifiers">[[syserr.errcondition.modifiers]]</a>
|
| 539 |
|
| 540 |
``` cpp
|
| 541 |
void assign(int val, const error_category& cat) noexcept;
|
|
@@ -546,16 +566,18 @@ void assign(int val, const error_category& cat) noexcept;
|
|
| 546 |
``` cpp
|
| 547 |
template <class ErrorConditionEnum>
|
| 548 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 549 |
```
|
| 550 |
|
| 551 |
-
`*this == make_error_condition(e)`.
|
| 552 |
|
| 553 |
*Returns:* `*this`.
|
| 554 |
|
| 555 |
-
*Remarks:*
|
| 556 |
-
|
|
|
|
|
|
|
| 557 |
|
| 558 |
``` cpp
|
| 559 |
void clear() noexcept;
|
| 560 |
```
|
| 561 |
|
|
@@ -593,20 +615,31 @@ explicit operator bool() const noexcept;
|
|
| 593 |
error_condition make_error_condition(errc e) noexcept;
|
| 594 |
```
|
| 595 |
|
| 596 |
*Returns:* `error_condition(static_cast<int>(e), generic_category())`.
|
| 597 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 598 |
``` cpp
|
| 599 |
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 600 |
```
|
| 601 |
|
| 602 |
*Returns:*
|
| 603 |
`lhs.category() < rhs.category() || lhs.category() == rhs.category() &&`
|
| 604 |
`lhs.value() < rhs.value()`.
|
| 605 |
|
| 606 |
-
### Comparison operators <a id="syserr.compare">[[syserr.compare]]</a>
|
| 607 |
-
|
| 608 |
``` cpp
|
| 609 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 610 |
```
|
| 611 |
|
| 612 |
*Returns:*
|
|
@@ -644,44 +677,42 @@ bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept
|
|
| 644 |
|
| 645 |
### System error hash support <a id="syserr.hash">[[syserr.hash]]</a>
|
| 646 |
|
| 647 |
``` cpp
|
| 648 |
template <> struct hash<error_code>;
|
|
|
|
| 649 |
```
|
| 650 |
|
| 651 |
-
The
|
| 652 |
-
template `hash` ([[unord.hash]]).
|
| 653 |
|
| 654 |
### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
|
| 655 |
|
| 656 |
#### Class `system_error` overview <a id="syserr.syserr.overview">[[syserr.syserr.overview]]</a>
|
| 657 |
|
| 658 |
The class `system_error` describes an exception object used to report
|
| 659 |
error conditions that have an associated error code. Such error
|
| 660 |
conditions typically originate from the operating system or other
|
| 661 |
low-level application program interfaces.
|
| 662 |
|
| 663 |
-
If an error represents an out-of-memory condition,
|
| 664 |
-
encouraged to throw an exception object of type
|
| 665 |
-
[[bad.alloc]] rather than `system_error`.
|
| 666 |
|
| 667 |
``` cpp
|
| 668 |
namespace std {
|
| 669 |
class system_error : public runtime_error {
|
| 670 |
public:
|
| 671 |
system_error(error_code ec, const string& what_arg);
|
| 672 |
system_error(error_code ec, const char* what_arg);
|
| 673 |
system_error(error_code ec);
|
| 674 |
-
system_error(int ev, const error_category& ecat,
|
| 675 |
-
|
| 676 |
-
system_error(int ev, const error_category& ecat,
|
| 677 |
-
const char* what_arg);
|
| 678 |
system_error(int ev, const error_category& ecat);
|
| 679 |
const error_code& code() const noexcept;
|
| 680 |
-
const char* what() const noexcept;
|
| 681 |
};
|
| 682 |
-
}
|
| 683 |
```
|
| 684 |
|
| 685 |
#### Class `system_error` members <a id="syserr.syserr.members">[[syserr.syserr.members]]</a>
|
| 686 |
|
| 687 |
``` cpp
|
|
@@ -711,23 +742,21 @@ system_error(error_code ec);
|
|
| 711 |
*Effects:* Constructs an object of class `system_error`.
|
| 712 |
|
| 713 |
*Postconditions:* `code() == ec`.
|
| 714 |
|
| 715 |
``` cpp
|
| 716 |
-
system_error(int ev, const error_category& ecat,
|
| 717 |
-
const string& what_arg);
|
| 718 |
```
|
| 719 |
|
| 720 |
*Effects:* Constructs an object of class `system_error`.
|
| 721 |
|
| 722 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
| 723 |
|
| 724 |
`string(what()).find(what_arg) != string::npos`.
|
| 725 |
|
| 726 |
``` cpp
|
| 727 |
-
system_error(int ev, const error_category& ecat,
|
| 728 |
-
const char* what_arg);
|
| 729 |
```
|
| 730 |
|
| 731 |
*Effects:* Constructs an object of class `system_error`.
|
| 732 |
|
| 733 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
|
@@ -748,23 +777,28 @@ const error_code& code() const noexcept;
|
|
| 748 |
|
| 749 |
*Returns:* `ec` or `error_code(ev, ecat)`, from the constructor, as
|
| 750 |
appropriate.
|
| 751 |
|
| 752 |
``` cpp
|
| 753 |
-
const char* what() const noexcept;
|
| 754 |
```
|
| 755 |
|
| 756 |
*Returns:* An NTBSincorporating the arguments supplied in the
|
| 757 |
constructor.
|
| 758 |
|
| 759 |
-
The returned
|
| 760 |
-
`what_arg + ": " + code.message()`.
|
| 761 |
|
| 762 |
<!-- Link reference definitions -->
|
| 763 |
[assertions]: #assertions
|
|
|
|
| 764 |
[bad.alloc]: language.md#bad.alloc
|
|
|
|
|
|
|
| 765 |
[comparisons]: utilities.md#comparisons
|
|
|
|
|
|
|
| 766 |
[diagnostics]: #diagnostics
|
| 767 |
[diagnostics.general]: #diagnostics.general
|
| 768 |
[domain.error]: #domain.error
|
| 769 |
[errno]: #errno
|
| 770 |
[invalid.argument]: #invalid.argument
|
|
@@ -774,10 +808,11 @@ The returned NTBS might be the contents of
|
|
| 774 |
[overflow.error]: #overflow.error
|
| 775 |
[range.error]: #range.error
|
| 776 |
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 777 |
[runtime.error]: #runtime.error
|
| 778 |
[std.exceptions]: #std.exceptions
|
|
|
|
| 779 |
[syserr]: #syserr
|
| 780 |
[syserr.compare]: #syserr.compare
|
| 781 |
[syserr.errcat]: #syserr.errcat
|
| 782 |
[syserr.errcat.derived]: #syserr.errcat.derived
|
| 783 |
[syserr.errcat.nonvirtuals]: #syserr.errcat.nonvirtuals
|
|
@@ -798,10 +833,9 @@ The returned NTBS might be the contents of
|
|
| 798 |
[syserr.errcondition.overview]: #syserr.errcondition.overview
|
| 799 |
[syserr.hash]: #syserr.hash
|
| 800 |
[syserr.syserr]: #syserr.syserr
|
| 801 |
[syserr.syserr.members]: #syserr.syserr.members
|
| 802 |
[syserr.syserr.overview]: #syserr.syserr.overview
|
| 803 |
-
[
|
| 804 |
-
[tab:diagnostics.hdr.cerrno]: #tab:diagnostics.hdr.cerrno
|
| 805 |
[tab:diagnostics.lib.summary]: #tab:diagnostics.lib.summary
|
| 806 |
[underflow.error]: #underflow.error
|
| 807 |
[unord.hash]: utilities.md#unord.hash
|
|
|
|
| 6 |
|
| 7 |
Components described in this subclause shall not change the value of
|
| 8 |
`errno` ([[errno]]). Implementations should leave the error states
|
| 9 |
provided by other libraries unchanged.
|
| 10 |
|
| 11 |
+
### Header `<system_error>` synopsis <a id="system_error.syn">[[system_error.syn]]</a>
|
| 12 |
+
|
| 13 |
``` cpp
|
| 14 |
namespace std {
|
| 15 |
class error_category;
|
| 16 |
const error_category& generic_category() noexcept;
|
| 17 |
const error_category& system_category() noexcept;
|
|
|
|
| 105 |
too_many_symbolic_link_levels, // ELOOP
|
| 106 |
value_too_large, // EOVERFLOW
|
| 107 |
wrong_protocol_type, // EPROTOTYPE
|
| 108 |
};
|
| 109 |
|
| 110 |
+
template <> struct is_error_condition_enum<errc> : true_type {};
|
| 111 |
|
| 112 |
+
// [syserr.errcode.nonmembers], non-member functions
|
| 113 |
error_code make_error_code(errc e) noexcept;
|
| 114 |
+
|
| 115 |
+
template <class charT, class traits>
|
| 116 |
+
basic_ostream<charT, traits>&
|
| 117 |
+
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 118 |
+
|
| 119 |
+
// [syserr.errcondition.nonmembers], non-member functions
|
| 120 |
error_condition make_error_condition(errc e) noexcept;
|
| 121 |
|
| 122 |
+
// [syserr.compare], comparison functions
|
| 123 |
+
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 124 |
+
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 125 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 126 |
bool operator==(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 127 |
bool operator==(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 128 |
bool operator==(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 129 |
bool operator!=(const error_code& lhs, const error_code& rhs) noexcept;
|
| 130 |
bool operator!=(const error_code& lhs, const error_condition& rhs) noexcept;
|
| 131 |
bool operator!=(const error_condition& lhs, const error_code& rhs) noexcept;
|
| 132 |
bool operator!=(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 133 |
|
| 134 |
+
// [syserr.hash], hash support
|
| 135 |
template <class T> struct hash;
|
| 136 |
template <> struct hash<error_code>;
|
| 137 |
+
template <> struct hash<error_condition>;
|
| 138 |
+
|
| 139 |
+
// [syserr], system error support
|
| 140 |
+
template <class T> inline constexpr bool is_error_code_enum_v
|
| 141 |
+
= is_error_code_enum<T>::value;
|
| 142 |
+
template <class T> inline constexpr bool is_error_condition_enum_v
|
| 143 |
+
= is_error_condition_enum<T>::value;
|
| 144 |
+
}
|
| 145 |
```
|
| 146 |
|
| 147 |
The value of each `enum errc` constant shall be the same as the value of
|
| 148 |
the `<cerrno>` macro shown in the above synopsis. Whether or not the
|
| 149 |
`<system_error>` implementation exposes the `<cerrno>` macros is
|
|
|
|
| 160 |
|
| 161 |
The class `error_category` serves as a base class for types used to
|
| 162 |
identify the source and encoding of a particular category of error code.
|
| 163 |
Classes may be derived from `error_category` to support categories of
|
| 164 |
errors in addition to those defined in this International Standard. Such
|
| 165 |
+
classes shall behave as specified in this subclause.
|
| 166 |
+
|
| 167 |
+
[*Note 1*: `error_category` objects are passed by reference, and two
|
| 168 |
+
such objects are equal if they have the same address. This means that
|
| 169 |
+
applications using custom `error_category` types should create a single
|
| 170 |
+
object of each such type. — *end note*]
|
| 171 |
|
| 172 |
``` cpp
|
| 173 |
namespace std {
|
| 174 |
class error_category {
|
| 175 |
public:
|
|
|
|
| 188 |
bool operator<(const error_category& rhs) const noexcept;
|
| 189 |
};
|
| 190 |
|
| 191 |
const error_category& generic_category() noexcept;
|
| 192 |
const error_category& system_category() noexcept;
|
| 193 |
+
}
|
|
|
|
| 194 |
```
|
| 195 |
|
| 196 |
#### Class `error_category` virtual members <a id="syserr.errcat.virtuals">[[syserr.errcat.virtuals]]</a>
|
| 197 |
|
| 198 |
``` cpp
|
|
|
|
| 255 |
bool operator<(const error_category& rhs) const noexcept;
|
| 256 |
```
|
| 257 |
|
| 258 |
*Returns:* `less<const error_category*>()(this, &rhs)`.
|
| 259 |
|
| 260 |
+
[*Note 1*: `less` ([[comparisons]]) provides a total ordering for
|
| 261 |
+
pointers. — *end note*]
|
| 262 |
|
| 263 |
#### Program defined classes derived from `error_category` <a id="syserr.errcat.derived">[[syserr.errcat.derived]]</a>
|
| 264 |
|
| 265 |
``` cpp
|
| 266 |
virtual const char* name() const noexcept = 0;
|
|
|
|
| 318 |
|
| 319 |
If the argument `ev` corresponds to a POSIX `errno` value `posv`, the
|
| 320 |
function shall return `error_condition(posv, generic_category())`.
|
| 321 |
Otherwise, the function shall return
|
| 322 |
`error_condition(ev, system_category())`. What constitutes
|
| 323 |
+
correspondence for any given operating system is unspecified.
|
| 324 |
+
|
| 325 |
+
[*Note 1*: The number of potential system error codes is large and
|
| 326 |
+
unbounded, and some may not correspond to any POSIX `errno` value. Thus
|
| 327 |
+
implementations are given latitude in determining
|
| 328 |
+
correspondence. — *end note*]
|
| 329 |
|
| 330 |
### Class `error_code` <a id="syserr.errcode">[[syserr.errcode]]</a>
|
| 331 |
|
| 332 |
#### Class `error_code` overview <a id="syserr.errcode.overview">[[syserr.errcode.overview]]</a>
|
| 333 |
|
| 334 |
The class `error_code` describes an object used to hold error code
|
| 335 |
values, such as those originating from the operating system or other
|
| 336 |
+
low-level application program interfaces.
|
| 337 |
+
|
| 338 |
+
[*Note 1*: Class `error_code` is an adjunct to error reporting by
|
| 339 |
+
exception. — *end note*]
|
| 340 |
|
| 341 |
``` cpp
|
| 342 |
namespace std {
|
| 343 |
class error_code {
|
| 344 |
public:
|
| 345 |
+
// [syserr.errcode.constructors], constructors
|
| 346 |
error_code() noexcept;
|
| 347 |
error_code(int val, const error_category& cat) noexcept;
|
| 348 |
template <class ErrorCodeEnum>
|
| 349 |
error_code(ErrorCodeEnum e) noexcept;
|
| 350 |
|
| 351 |
+
// [syserr.errcode.modifiers], modifiers
|
| 352 |
void assign(int val, const error_category& cat) noexcept;
|
| 353 |
template <class ErrorCodeEnum>
|
| 354 |
error_code& operator=(ErrorCodeEnum e) noexcept;
|
| 355 |
void clear() noexcept;
|
| 356 |
|
| 357 |
+
// [syserr.errcode.observers], observers
|
| 358 |
int value() const noexcept;
|
| 359 |
const error_category& category() const noexcept;
|
| 360 |
error_condition default_error_condition() const noexcept;
|
| 361 |
string message() const;
|
| 362 |
explicit operator bool() const noexcept;
|
|
|
|
| 364 |
private:
|
| 365 |
int val_; // exposition only
|
| 366 |
const error_category* cat_; // exposition only
|
| 367 |
};
|
| 368 |
|
| 369 |
+
// [syserr.errcode.nonmembers], non-member functions
|
| 370 |
error_code make_error_code(errc e) noexcept;
|
|
|
|
| 371 |
|
| 372 |
template <class charT, class traits>
|
| 373 |
basic_ostream<charT, traits>&
|
| 374 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 375 |
+
}
|
| 376 |
```
|
| 377 |
|
| 378 |
#### Class `error_code` constructors <a id="syserr.errcode.constructors">[[syserr.errcode.constructors]]</a>
|
| 379 |
|
| 380 |
``` cpp
|
|
|
|
| 400 |
|
| 401 |
*Effects:* Constructs an object of type `error_code`.
|
| 402 |
|
| 403 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 404 |
|
| 405 |
+
*Remarks:*
|
| 406 |
+
|
| 407 |
+
This constructor shall not participate in overload resolution unless
|
| 408 |
+
`is_error_code_enum_v<ErrorCodeEnum>` is `true`.
|
| 409 |
|
| 410 |
#### Class `error_code` modifiers <a id="syserr.errcode.modifiers">[[syserr.errcode.modifiers]]</a>
|
| 411 |
|
| 412 |
``` cpp
|
| 413 |
void assign(int val, const error_category& cat) noexcept;
|
|
|
|
| 422 |
|
| 423 |
*Postconditions:* `*this == make_error_code(e)`.
|
| 424 |
|
| 425 |
*Returns:* `*this`.
|
| 426 |
|
| 427 |
+
*Remarks:*
|
| 428 |
+
|
| 429 |
+
This operator shall not participate in overload resolution unless
|
| 430 |
+
`is_error_code_enum_v<ErrorCodeEnum>` is `true`.
|
| 431 |
|
| 432 |
``` cpp
|
| 433 |
void clear() noexcept;
|
| 434 |
```
|
| 435 |
|
|
|
|
| 473 |
error_code make_error_code(errc e) noexcept;
|
| 474 |
```
|
| 475 |
|
| 476 |
*Returns:* `error_code(static_cast<int>(e), generic_category())`.
|
| 477 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 478 |
``` cpp
|
| 479 |
template <class charT, class traits>
|
| 480 |
basic_ostream<charT, traits>&
|
| 481 |
operator<<(basic_ostream<charT, traits>& os, const error_code& ec);
|
| 482 |
```
|
| 483 |
|
| 484 |
+
*Effects:* As if by: `os << ec.category().name() << ’:’ << ec.value();`
|
|
|
|
| 485 |
|
| 486 |
### Class `error_condition` <a id="syserr.errcondition">[[syserr.errcondition]]</a>
|
| 487 |
|
| 488 |
#### Class `error_condition` overview <a id="syserr.errcondition.overview">[[syserr.errcondition.overview]]</a>
|
| 489 |
|
| 490 |
The class `error_condition` describes an object used to hold values
|
| 491 |
+
identifying error conditions.
|
| 492 |
+
|
| 493 |
+
[*Note 1*: `error_condition` values are portable abstractions, while
|
| 494 |
+
`error_code` values ([[syserr.errcode]]) are implementation
|
| 495 |
+
specific. — *end note*]
|
| 496 |
|
| 497 |
``` cpp
|
| 498 |
namespace std {
|
| 499 |
class error_condition {
|
| 500 |
public:
|
| 501 |
+
// [syserr.errcondition.constructors], constructors
|
| 502 |
error_condition() noexcept;
|
| 503 |
error_condition(int val, const error_category& cat) noexcept;
|
| 504 |
template <class ErrorConditionEnum>
|
| 505 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 506 |
|
| 507 |
+
// [syserr.errcondition.modifiers], modifiers
|
| 508 |
void assign(int val, const error_category& cat) noexcept;
|
| 509 |
template <class ErrorConditionEnum>
|
| 510 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 511 |
void clear() noexcept;
|
| 512 |
|
| 513 |
+
// [syserr.errcondition.observers], observers
|
| 514 |
int value() const noexcept;
|
| 515 |
const error_category& category() const noexcept;
|
| 516 |
string message() const;
|
| 517 |
explicit operator bool() const noexcept;
|
| 518 |
|
| 519 |
private:
|
| 520 |
int val_; // exposition only
|
| 521 |
const error_category* cat_; // exposition only
|
| 522 |
};
|
| 523 |
+
}
|
|
|
|
|
|
|
|
|
|
| 524 |
```
|
| 525 |
|
| 526 |
#### Class `error_condition` constructors <a id="syserr.errcondition.constructors">[[syserr.errcondition.constructors]]</a>
|
| 527 |
|
| 528 |
``` cpp
|
|
|
|
| 546 |
error_condition(ErrorConditionEnum e) noexcept;
|
| 547 |
```
|
| 548 |
|
| 549 |
*Effects:* Constructs an object of type `error_condition`.
|
| 550 |
|
| 551 |
+
*Postconditions:* `*this == make_error_condition(e)`.
|
| 552 |
|
| 553 |
+
*Remarks:*
|
| 554 |
+
|
| 555 |
+
This constructor shall not participate in overload resolution unless
|
| 556 |
+
`is_error_condition_enum_v<ErrorConditionEnum>` is `true`.
|
| 557 |
|
| 558 |
#### Class `error_condition` modifiers <a id="syserr.errcondition.modifiers">[[syserr.errcondition.modifiers]]</a>
|
| 559 |
|
| 560 |
``` cpp
|
| 561 |
void assign(int val, const error_category& cat) noexcept;
|
|
|
|
| 566 |
``` cpp
|
| 567 |
template <class ErrorConditionEnum>
|
| 568 |
error_condition& operator=(ErrorConditionEnum e) noexcept;
|
| 569 |
```
|
| 570 |
|
| 571 |
+
*Postconditions:* `*this == make_error_condition(e)`.
|
| 572 |
|
| 573 |
*Returns:* `*this`.
|
| 574 |
|
| 575 |
+
*Remarks:*
|
| 576 |
+
|
| 577 |
+
This operator shall not participate in overload resolution unless
|
| 578 |
+
`is_error_condition_enum_v<ErrorConditionEnum>` is `true`.
|
| 579 |
|
| 580 |
``` cpp
|
| 581 |
void clear() noexcept;
|
| 582 |
```
|
| 583 |
|
|
|
|
| 615 |
error_condition make_error_condition(errc e) noexcept;
|
| 616 |
```
|
| 617 |
|
| 618 |
*Returns:* `error_condition(static_cast<int>(e), generic_category())`.
|
| 619 |
|
| 620 |
+
### Comparison functions <a id="syserr.compare">[[syserr.compare]]</a>
|
| 621 |
+
|
| 622 |
+
``` cpp
|
| 623 |
+
bool operator<(const error_code& lhs, const error_code& rhs) noexcept;
|
| 624 |
+
```
|
| 625 |
+
|
| 626 |
+
*Returns:*
|
| 627 |
+
|
| 628 |
+
``` cpp
|
| 629 |
+
lhs.category() < rhs.category() ||
|
| 630 |
+
(lhs.category() == rhs.category() && lhs.value() < rhs.value());
|
| 631 |
+
```
|
| 632 |
+
|
| 633 |
``` cpp
|
| 634 |
bool operator<(const error_condition& lhs, const error_condition& rhs) noexcept;
|
| 635 |
```
|
| 636 |
|
| 637 |
*Returns:*
|
| 638 |
`lhs.category() < rhs.category() || lhs.category() == rhs.category() &&`
|
| 639 |
`lhs.value() < rhs.value()`.
|
| 640 |
|
|
|
|
|
|
|
| 641 |
``` cpp
|
| 642 |
bool operator==(const error_code& lhs, const error_code& rhs) noexcept;
|
| 643 |
```
|
| 644 |
|
| 645 |
*Returns:*
|
|
|
|
| 677 |
|
| 678 |
### System error hash support <a id="syserr.hash">[[syserr.hash]]</a>
|
| 679 |
|
| 680 |
``` cpp
|
| 681 |
template <> struct hash<error_code>;
|
| 682 |
+
template <> struct hash<error_condition>;
|
| 683 |
```
|
| 684 |
|
| 685 |
+
The specializations are enabled ([[unord.hash]]).
|
|
|
|
| 686 |
|
| 687 |
### Class `system_error` <a id="syserr.syserr">[[syserr.syserr]]</a>
|
| 688 |
|
| 689 |
#### Class `system_error` overview <a id="syserr.syserr.overview">[[syserr.syserr.overview]]</a>
|
| 690 |
|
| 691 |
The class `system_error` describes an exception object used to report
|
| 692 |
error conditions that have an associated error code. Such error
|
| 693 |
conditions typically originate from the operating system or other
|
| 694 |
low-level application program interfaces.
|
| 695 |
|
| 696 |
+
[*Note 1*: If an error represents an out-of-memory condition,
|
| 697 |
+
implementations are encouraged to throw an exception object of type
|
| 698 |
+
`bad_alloc` ([[bad.alloc]]) rather than `system_error`. — *end note*]
|
| 699 |
|
| 700 |
``` cpp
|
| 701 |
namespace std {
|
| 702 |
class system_error : public runtime_error {
|
| 703 |
public:
|
| 704 |
system_error(error_code ec, const string& what_arg);
|
| 705 |
system_error(error_code ec, const char* what_arg);
|
| 706 |
system_error(error_code ec);
|
| 707 |
+
system_error(int ev, const error_category& ecat, const string& what_arg);
|
| 708 |
+
system_error(int ev, const error_category& ecat, const char* what_arg);
|
|
|
|
|
|
|
| 709 |
system_error(int ev, const error_category& ecat);
|
| 710 |
const error_code& code() const noexcept;
|
| 711 |
+
const char* what() const noexcept override;
|
| 712 |
};
|
| 713 |
+
}
|
| 714 |
```
|
| 715 |
|
| 716 |
#### Class `system_error` members <a id="syserr.syserr.members">[[syserr.syserr.members]]</a>
|
| 717 |
|
| 718 |
``` cpp
|
|
|
|
| 742 |
*Effects:* Constructs an object of class `system_error`.
|
| 743 |
|
| 744 |
*Postconditions:* `code() == ec`.
|
| 745 |
|
| 746 |
``` cpp
|
| 747 |
+
system_error(int ev, const error_category& ecat, const string& what_arg);
|
|
|
|
| 748 |
```
|
| 749 |
|
| 750 |
*Effects:* Constructs an object of class `system_error`.
|
| 751 |
|
| 752 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
| 753 |
|
| 754 |
`string(what()).find(what_arg) != string::npos`.
|
| 755 |
|
| 756 |
``` cpp
|
| 757 |
+
system_error(int ev, const error_category& ecat, const char* what_arg);
|
|
|
|
| 758 |
```
|
| 759 |
|
| 760 |
*Effects:* Constructs an object of class `system_error`.
|
| 761 |
|
| 762 |
*Postconditions:* `code() == error_code(ev, ecat)`.
|
|
|
|
| 777 |
|
| 778 |
*Returns:* `ec` or `error_code(ev, ecat)`, from the constructor, as
|
| 779 |
appropriate.
|
| 780 |
|
| 781 |
``` cpp
|
| 782 |
+
const char* what() const noexcept override;
|
| 783 |
```
|
| 784 |
|
| 785 |
*Returns:* An NTBSincorporating the arguments supplied in the
|
| 786 |
constructor.
|
| 787 |
|
| 788 |
+
[*Note 1*: The returned NTBSmight be the contents of
|
| 789 |
+
`what_arg + ": " + code.message()`. — *end note*]
|
| 790 |
|
| 791 |
<!-- Link reference definitions -->
|
| 792 |
[assertions]: #assertions
|
| 793 |
+
[assertions.assert]: #assertions.assert
|
| 794 |
[bad.alloc]: language.md#bad.alloc
|
| 795 |
+
[cassert.syn]: #cassert.syn
|
| 796 |
+
[cerrno.syn]: #cerrno.syn
|
| 797 |
[comparisons]: utilities.md#comparisons
|
| 798 |
+
[conv]: conv.md#conv
|
| 799 |
+
[defns.const.subexpr]: library.md#defns.const.subexpr
|
| 800 |
[diagnostics]: #diagnostics
|
| 801 |
[diagnostics.general]: #diagnostics.general
|
| 802 |
[domain.error]: #domain.error
|
| 803 |
[errno]: #errno
|
| 804 |
[invalid.argument]: #invalid.argument
|
|
|
|
| 808 |
[overflow.error]: #overflow.error
|
| 809 |
[range.error]: #range.error
|
| 810 |
[res.on.exception.handling]: library.md#res.on.exception.handling
|
| 811 |
[runtime.error]: #runtime.error
|
| 812 |
[std.exceptions]: #std.exceptions
|
| 813 |
+
[stdexcept.syn]: #stdexcept.syn
|
| 814 |
[syserr]: #syserr
|
| 815 |
[syserr.compare]: #syserr.compare
|
| 816 |
[syserr.errcat]: #syserr.errcat
|
| 817 |
[syserr.errcat.derived]: #syserr.errcat.derived
|
| 818 |
[syserr.errcat.nonvirtuals]: #syserr.errcat.nonvirtuals
|
|
|
|
| 833 |
[syserr.errcondition.overview]: #syserr.errcondition.overview
|
| 834 |
[syserr.hash]: #syserr.hash
|
| 835 |
[syserr.syserr]: #syserr.syserr
|
| 836 |
[syserr.syserr.members]: #syserr.syserr.members
|
| 837 |
[syserr.syserr.overview]: #syserr.syserr.overview
|
| 838 |
+
[system_error.syn]: #system_error.syn
|
|
|
|
| 839 |
[tab:diagnostics.lib.summary]: #tab:diagnostics.lib.summary
|
| 840 |
[underflow.error]: #underflow.error
|
| 841 |
[unord.hash]: utilities.md#unord.hash
|