tmp/tmp8tseoaw9/{from.md → to.md}
RENAMED
|
@@ -1,13 +1,16 @@
|
|
| 1 |
## Exception handling <a id="support.exception">[[support.exception]]</a>
|
| 2 |
|
|
|
|
|
|
|
| 3 |
The header `<exception>` defines several types and functions related to
|
| 4 |
the handling of exceptions in a C++ program.
|
| 5 |
|
| 6 |
### Header `<exception>` synopsis <a id="exception.syn">[[exception.syn]]</a>
|
| 7 |
|
| 8 |
``` cpp
|
|
|
|
| 9 |
namespace std {
|
| 10 |
class exception;
|
| 11 |
class bad_exception;
|
| 12 |
class nested_exception;
|
| 13 |
|
|
@@ -83,11 +86,11 @@ virtual const char* what() const noexcept;
|
|
| 83 |
|
| 84 |
*Returns:* An *implementation-defined* NTBS.
|
| 85 |
|
| 86 |
*Remarks:* The message may be a null-terminated multibyte
|
| 87 |
string [[multibyte.strings]], suitable for conversion and display as a
|
| 88 |
-
`wstring`
|
| 89 |
remains valid until the exception object from which it is obtained is
|
| 90 |
destroyed or a non-`const` member function of the exception object is
|
| 91 |
called.
|
| 92 |
|
| 93 |
### Class `bad_exception` <a id="bad.exception">[[bad.exception]]</a>
|
|
@@ -119,11 +122,11 @@ const char* what() const noexcept override;
|
|
| 119 |
|
| 120 |
``` cpp
|
| 121 |
using terminate_handler = void (*)();
|
| 122 |
```
|
| 123 |
|
| 124 |
-
The type of a *handler function* to be
|
| 125 |
terminating exception processing.
|
| 126 |
|
| 127 |
*Required behavior:* A `terminate_handler` shall terminate execution of
|
| 128 |
the program without returning to the caller.
|
| 129 |
|
|
@@ -137,43 +140,43 @@ terminate_handler set_terminate(terminate_handler f) noexcept;
|
|
| 137 |
```
|
| 138 |
|
| 139 |
*Effects:* Establishes the function designated by `f` as the current
|
| 140 |
handler function for terminating exception processing.
|
| 141 |
|
|
|
|
|
|
|
| 142 |
*Remarks:* It is unspecified whether a null pointer value designates the
|
| 143 |
default `terminate_handler`.
|
| 144 |
|
| 145 |
-
*Returns:* The previous `terminate_handler`.
|
| 146 |
-
|
| 147 |
#### `get_terminate` <a id="get.terminate">[[get.terminate]]</a>
|
| 148 |
|
| 149 |
``` cpp
|
| 150 |
terminate_handler get_terminate() noexcept;
|
| 151 |
```
|
| 152 |
|
| 153 |
*Returns:* The current `terminate_handler`.
|
| 154 |
|
| 155 |
-
[*Note 1*: This
|
| 156 |
|
| 157 |
#### `terminate` <a id="terminate">[[terminate]]</a>
|
| 158 |
|
| 159 |
``` cpp
|
| 160 |
[[noreturn]] void terminate() noexcept;
|
| 161 |
```
|
| 162 |
|
| 163 |
-
*Remarks:* Called by the implementation when exception handling must be
|
| 164 |
-
abandoned for any of several reasons [[except.terminate]]. May also be
|
| 165 |
-
called directly by the program.
|
| 166 |
-
|
| 167 |
*Effects:* Calls a `terminate_handler` function. It is unspecified which
|
| 168 |
`terminate_handler` function will be called if an exception is active
|
| 169 |
during a call to `set_terminate`. Otherwise calls the current
|
| 170 |
`terminate_handler` function.
|
| 171 |
|
| 172 |
[*Note 1*: A default `terminate_handler` is always considered a
|
| 173 |
callable handler in this context. — *end note*]
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
### `uncaught_exceptions` <a id="uncaught.exceptions">[[uncaught.exceptions]]</a>
|
| 176 |
|
| 177 |
``` cpp
|
| 178 |
int uncaught_exceptions() noexcept;
|
| 179 |
```
|
|
@@ -201,22 +204,22 @@ The default constructor of `exception_ptr` produces the null value of
|
|
| 201 |
the type.
|
| 202 |
|
| 203 |
`exception_ptr` shall not be implicitly convertible to any arithmetic,
|
| 204 |
enumeration, or pointer type.
|
| 205 |
|
| 206 |
-
[*Note 1*: An implementation
|
| 207 |
-
|
| 208 |
|
| 209 |
For purposes of determining the presence of a data race, operations on
|
| 210 |
`exception_ptr` objects shall access and modify only the `exception_ptr`
|
| 211 |
objects themselves and not the exceptions they refer to. Use of
|
| 212 |
`rethrow_exception` on `exception_ptr` objects that refer to the same
|
| 213 |
exception object shall not introduce a data race.
|
| 214 |
|
| 215 |
[*Note 2*: If `rethrow_exception` rethrows the same exception object
|
| 216 |
(rather than a copy), concurrent access to that rethrown exception
|
| 217 |
-
object
|
| 218 |
`exception_ptr` objects that refer to a particular exception do not
|
| 219 |
introduce a data race. — *end note*]
|
| 220 |
|
| 221 |
``` cpp
|
| 222 |
exception_ptr current_exception() noexcept;
|
|
@@ -238,21 +241,29 @@ creates a new copy each time it is called. — *end note*]
|
|
| 238 |
If the attempt to copy the current exception object throws an exception,
|
| 239 |
the function returns an `exception_ptr` object that refers to the thrown
|
| 240 |
exception or, if this is not possible, to an instance of
|
| 241 |
`bad_exception`.
|
| 242 |
|
| 243 |
-
[*Note 4*: The copy constructor of the thrown exception
|
| 244 |
so the implementation is allowed to substitute a `bad_exception` object
|
| 245 |
to avoid infinite recursion. — *end note*]
|
| 246 |
|
| 247 |
``` cpp
|
| 248 |
[[noreturn]] void rethrow_exception(exception_ptr p);
|
| 249 |
```
|
| 250 |
|
| 251 |
*Preconditions:* `p` is not a null pointer.
|
| 252 |
|
| 253 |
-
*
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 254 |
|
| 255 |
``` cpp
|
| 256 |
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
|
| 257 |
```
|
| 258 |
|
|
|
|
| 1 |
## Exception handling <a id="support.exception">[[support.exception]]</a>
|
| 2 |
|
| 3 |
+
### General <a id="support.exception.general">[[support.exception.general]]</a>
|
| 4 |
+
|
| 5 |
The header `<exception>` defines several types and functions related to
|
| 6 |
the handling of exceptions in a C++ program.
|
| 7 |
|
| 8 |
### Header `<exception>` synopsis <a id="exception.syn">[[exception.syn]]</a>
|
| 9 |
|
| 10 |
``` cpp
|
| 11 |
+
// all freestanding
|
| 12 |
namespace std {
|
| 13 |
class exception;
|
| 14 |
class bad_exception;
|
| 15 |
class nested_exception;
|
| 16 |
|
|
|
|
| 86 |
|
| 87 |
*Returns:* An *implementation-defined* NTBS.
|
| 88 |
|
| 89 |
*Remarks:* The message may be a null-terminated multibyte
|
| 90 |
string [[multibyte.strings]], suitable for conversion and display as a
|
| 91 |
+
`wstring` [[string.classes]], [[locale.codecvt]]. The return value
|
| 92 |
remains valid until the exception object from which it is obtained is
|
| 93 |
destroyed or a non-`const` member function of the exception object is
|
| 94 |
called.
|
| 95 |
|
| 96 |
### Class `bad_exception` <a id="bad.exception">[[bad.exception]]</a>
|
|
|
|
| 122 |
|
| 123 |
``` cpp
|
| 124 |
using terminate_handler = void (*)();
|
| 125 |
```
|
| 126 |
|
| 127 |
+
The type of a *handler function* to be invoked by `terminate` when
|
| 128 |
terminating exception processing.
|
| 129 |
|
| 130 |
*Required behavior:* A `terminate_handler` shall terminate execution of
|
| 131 |
the program without returning to the caller.
|
| 132 |
|
|
|
|
| 140 |
```
|
| 141 |
|
| 142 |
*Effects:* Establishes the function designated by `f` as the current
|
| 143 |
handler function for terminating exception processing.
|
| 144 |
|
| 145 |
+
*Returns:* The previous `terminate_handler`.
|
| 146 |
+
|
| 147 |
*Remarks:* It is unspecified whether a null pointer value designates the
|
| 148 |
default `terminate_handler`.
|
| 149 |
|
|
|
|
|
|
|
| 150 |
#### `get_terminate` <a id="get.terminate">[[get.terminate]]</a>
|
| 151 |
|
| 152 |
``` cpp
|
| 153 |
terminate_handler get_terminate() noexcept;
|
| 154 |
```
|
| 155 |
|
| 156 |
*Returns:* The current `terminate_handler`.
|
| 157 |
|
| 158 |
+
[*Note 1*: This can be a null pointer value. — *end note*]
|
| 159 |
|
| 160 |
#### `terminate` <a id="terminate">[[terminate]]</a>
|
| 161 |
|
| 162 |
``` cpp
|
| 163 |
[[noreturn]] void terminate() noexcept;
|
| 164 |
```
|
| 165 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 166 |
*Effects:* Calls a `terminate_handler` function. It is unspecified which
|
| 167 |
`terminate_handler` function will be called if an exception is active
|
| 168 |
during a call to `set_terminate`. Otherwise calls the current
|
| 169 |
`terminate_handler` function.
|
| 170 |
|
| 171 |
[*Note 1*: A default `terminate_handler` is always considered a
|
| 172 |
callable handler in this context. — *end note*]
|
| 173 |
|
| 174 |
+
*Remarks:* Called by the implementation when exception handling must be
|
| 175 |
+
abandoned for any of several reasons [[except.terminate]]. May also be
|
| 176 |
+
called directly by the program.
|
| 177 |
+
|
| 178 |
### `uncaught_exceptions` <a id="uncaught.exceptions">[[uncaught.exceptions]]</a>
|
| 179 |
|
| 180 |
``` cpp
|
| 181 |
int uncaught_exceptions() noexcept;
|
| 182 |
```
|
|
|
|
| 204 |
the type.
|
| 205 |
|
| 206 |
`exception_ptr` shall not be implicitly convertible to any arithmetic,
|
| 207 |
enumeration, or pointer type.
|
| 208 |
|
| 209 |
+
[*Note 1*: An implementation can use a reference-counted smart pointer
|
| 210 |
+
as `exception_ptr`. — *end note*]
|
| 211 |
|
| 212 |
For purposes of determining the presence of a data race, operations on
|
| 213 |
`exception_ptr` objects shall access and modify only the `exception_ptr`
|
| 214 |
objects themselves and not the exceptions they refer to. Use of
|
| 215 |
`rethrow_exception` on `exception_ptr` objects that refer to the same
|
| 216 |
exception object shall not introduce a data race.
|
| 217 |
|
| 218 |
[*Note 2*: If `rethrow_exception` rethrows the same exception object
|
| 219 |
(rather than a copy), concurrent access to that rethrown exception
|
| 220 |
+
object can introduce a data race. Changes in the number of
|
| 221 |
`exception_ptr` objects that refer to a particular exception do not
|
| 222 |
introduce a data race. — *end note*]
|
| 223 |
|
| 224 |
``` cpp
|
| 225 |
exception_ptr current_exception() noexcept;
|
|
|
|
| 241 |
If the attempt to copy the current exception object throws an exception,
|
| 242 |
the function returns an `exception_ptr` object that refers to the thrown
|
| 243 |
exception or, if this is not possible, to an instance of
|
| 244 |
`bad_exception`.
|
| 245 |
|
| 246 |
+
[*Note 4*: The copy constructor of the thrown exception can also fail,
|
| 247 |
so the implementation is allowed to substitute a `bad_exception` object
|
| 248 |
to avoid infinite recursion. — *end note*]
|
| 249 |
|
| 250 |
``` cpp
|
| 251 |
[[noreturn]] void rethrow_exception(exception_ptr p);
|
| 252 |
```
|
| 253 |
|
| 254 |
*Preconditions:* `p` is not a null pointer.
|
| 255 |
|
| 256 |
+
*Effects:* Let u be the exception object to which `p` refers, or a copy
|
| 257 |
+
of that exception object. It is unspecified whether a copy is made, and
|
| 258 |
+
memory for the copy is allocated in an unspecified way.
|
| 259 |
+
|
| 260 |
+
- If allocating memory to form u fails, throws an instance of
|
| 261 |
+
`bad_alloc`;
|
| 262 |
+
- otherwise, if copying the exception to which `p` refers to form u
|
| 263 |
+
throws an exception, throws that exception;
|
| 264 |
+
- otherwise, throws u.
|
| 265 |
|
| 266 |
``` cpp
|
| 267 |
template<class E> exception_ptr make_exception_ptr(E e) noexcept;
|
| 268 |
```
|
| 269 |
|