From Jason Turner

[support.exception]

Diff to HTML by rtfpessoa

Files changed (1) hide show
  1. tmp/tmpcgsxnulb/{from.md → to.md} +75 -63
tmp/tmpcgsxnulb/{from.md → to.md} RENAMED
@@ -1,29 +1,26 @@
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
  ``` cpp
7
  namespace std {
8
  class exception;
9
  class bad_exception;
10
  class nested_exception;
11
 
12
- typedef void (*unexpected_handler)();
13
- unexpected_handler get_unexpected() noexcept;
14
- unexpected_handler set_unexpected(unexpected_handler f) noexcept;
15
- [[noreturn]] void unexpected();
16
-
17
- typedef void (*terminate_handler)();
18
  terminate_handler get_terminate() noexcept;
19
  terminate_handler set_terminate(terminate_handler f) noexcept;
20
  [[noreturn]] void terminate() noexcept;
21
 
22
- bool uncaught_exception() noexcept;
23
 
24
- typedef unspecified exception_ptr;
25
 
26
  exception_ptr current_exception() noexcept;
27
  [[noreturn]] void rethrow_exception(exception_ptr p);
28
  template<class E> exception_ptr make_exception_ptr(E e) noexcept;
29
 
@@ -71,11 +68,12 @@ exception(const exception& rhs) noexcept;
71
  exception& operator=(const exception& rhs) noexcept;
72
  ```
73
 
74
  *Effects:* Copies an `exception` object.
75
 
76
- If `*this` and `rhs` both have dynamic type `exception` then
 
77
  `strcmp(what(), rhs.what())` shall equal 0.
78
 
79
  ``` cpp
80
  virtual ~exception();
81
  ```
@@ -102,36 +100,35 @@ namespace std {
102
  class bad_exception : public exception {
103
  public:
104
  bad_exception() noexcept;
105
  bad_exception(const bad_exception&) noexcept;
106
  bad_exception& operator=(const bad_exception&) noexcept;
107
- virtual const char* what() const noexcept;
108
  };
109
  }
110
  ```
111
 
112
- The class `bad_exception` defines the type of objects thrown as
113
- described in ([[except.unexpected]]).
 
 
114
 
115
  ``` cpp
116
  bad_exception() noexcept;
117
  ```
118
 
119
  *Effects:* Constructs an object of class `bad_exception`.
120
 
121
- *Remarks:* The result of calling `what()` on the newly constructed
122
- object is implementation-defined.
123
-
124
  ``` cpp
125
  bad_exception(const bad_exception&) noexcept;
126
  bad_exception& operator=(const bad_exception&) noexcept;
127
  ```
128
 
129
  *Effects:* Copies an object of class `bad_exception`.
130
 
131
  ``` cpp
132
- virtual const char* what() const noexcept;
133
  ```
134
 
135
  *Returns:* An *implementation-defined* NTBS.
136
 
137
  *Remarks:* The message may be a null-terminated multibyte
@@ -141,11 +138,11 @@ a `wstring` ([[string.classes]], [[locale.codecvt]]).
141
  ### Abnormal termination <a id="exception.terminate">[[exception.terminate]]</a>
142
 
143
  #### Type `terminate_handler` <a id="terminate.handler">[[terminate.handler]]</a>
144
 
145
  ``` cpp
146
- typedef void (*terminate_handler)();
147
  ```
148
 
149
  The type of a *handler function* to be called by `std::terminate()` when
150
  terminating exception processing.
151
 
@@ -173,51 +170,51 @@ default `terminate_handler`.
173
 
174
  ``` cpp
175
  terminate_handler get_terminate() noexcept;
176
  ```
177
 
178
- *Returns:* The current `terminate_handler`. This may be a null pointer
179
- value.
 
180
 
181
  #### `terminate` <a id="terminate">[[terminate]]</a>
182
 
183
  ``` cpp
184
  [[noreturn]] void terminate() noexcept;
185
  ```
186
 
187
  *Remarks:* Called by the implementation when exception handling must be
188
- abandoned for any of several reasons ([[except.terminate]]), in effect
189
- immediately after throwing the exception. May also be called directly by
190
- the program.
191
 
192
- *Effects:* Calls the current `terminate_handler` function. A default
193
- `terminate_handler` is always considered a callable handler in this
194
- context.
 
195
 
196
- ### `uncaught_exception` <a id="uncaught">[[uncaught]]</a>
 
 
 
197
 
198
  ``` cpp
199
- bool uncaught_exception() noexcept;
200
  ```
201
 
202
- *Returns:* `true` after the current thread has initialized an exception
203
- object ([[except.throw]]) until a handler for the exception (including
204
- `std::unexpected()` or `std::terminate()`) is
205
- activated ([[except.handle]]). This includes stack
206
- unwinding ([[except.ctor]]).
207
 
208
- *Remarks:* When `uncaught_exception()` returns `true`, throwing an
209
- exception can result in a call of
210
  `std::terminate()` ([[except.terminate]]).
211
 
212
  ### Exception propagation <a id="propagation">[[propagation]]</a>
213
 
214
  ``` cpp
215
- typedef unspecified exception_ptr;
216
  ```
217
 
218
- The type exception_ptr can be used to refer to an exception object.
219
 
220
  `exception_ptr` shall satisfy the requirements of
221
  `NullablePointer` ([[nullablepointer.requirements]]).
222
 
223
  Two non-null values of type `exception_ptr` are equivalent and compare
@@ -227,22 +224,24 @@ The default constructor of `exception_ptr` produces the null value of
227
  the type.
228
 
229
  `exception_ptr` shall not be implicitly convertible to any arithmetic,
230
  enumeration, or pointer type.
231
 
232
- An implementation might use a reference-counted smart pointer as
233
- `exception_ptr`.
234
 
235
  For purposes of determining the presence of a data race, operations on
236
  `exception_ptr` objects shall access and modify only the `exception_ptr`
237
  objects themselves and not the exceptions they refer to. Use of
238
  `rethrow_exception` on `exception_ptr` objects that refer to the same
239
- exception object shall not introduce a data race. if `rethrow_exception`
240
- rethrows the same exception object (rather than a copy), concurrent
241
- access to that rethrown exception object may introduce a data race.
242
- Changes in the number of `exception_ptr` objects that refer to a
243
- particular exception do not introduce a data race.
 
 
244
 
245
  ``` cpp
246
  exception_ptr current_exception() noexcept;
247
  ```
248
 
@@ -252,43 +251,49 @@ handled exception, or a null `exception_ptr` object if no exception is
252
  being handled. The referenced object shall remain valid at least as long
253
  as there is an `exception_ptr` object that refers to it. If the function
254
  needs to allocate memory and the attempt fails, it returns an
255
  `exception_ptr` object that refers to an instance of `bad_alloc`. It is
256
  unspecified whether the return values of two successive calls to
257
- `current_exception` refer to the same exception object. That is, it is
258
- unspecified whether `current_exception` creates a new copy each time it
259
- is called. If the attempt to copy the current exception object throws an
260
- exception, the function returns an `exception_ptr` object that refers to
261
- the thrown exception or, if this is not possible, to an instance of
262
- `bad_exception`. The copy constructor of the thrown exception may also
263
- fail, so the implementation is allowed to substitute a `bad_exception`
264
- object to avoid infinite recursion.
 
 
 
 
 
265
 
266
  ``` cpp
267
  [[noreturn]] void rethrow_exception(exception_ptr p);
268
  ```
269
 
270
  *Requires:* `p` shall not be a null pointer.
271
 
272
- *Throws:* the exception object to which `p` refers.
273
 
274
  ``` cpp
275
  template<class E> exception_ptr make_exception_ptr(E e) noexcept;
276
  ```
277
 
278
  *Effects:* Creates an `exception_ptr` object that refers to a copy of
279
- `e`, as if
280
 
281
  ``` cpp
282
  try {
283
  throw e;
284
  } catch(...) {
285
  return current_exception();
286
  }
287
  ```
288
 
289
- This function is provided for convenience and efficiency reasons.
 
290
 
291
  ### `nested_exception` <a id="except.nested">[[except.nested]]</a>
292
 
293
  ``` cpp
294
  namespace std {
@@ -311,12 +316,13 @@ namespace std {
311
 
312
  The class `nested_exception` is designed for use as a mixin through
313
  multiple inheritance. It captures the currently handled exception and
314
  stores it for later use.
315
 
316
- `nested_exception` has a virtual destructor to make it a polymorphic
317
- class. Its presence can be tested for with `dynamic_cast`.
 
318
 
319
  ``` cpp
320
  nested_exception() noexcept;
321
  ```
322
 
@@ -340,22 +346,28 @@ object.
340
 
341
  ``` cpp
342
  template <class T> [[noreturn]] void throw_with_nested(T&& t);
343
  ```
344
 
345
- Let `U` be `remove_reference_t<T>`.
346
 
347
  *Requires:* `U` shall be `CopyConstructible`.
348
 
349
- *Throws:* if `U` is a non-union class type not derived from
350
- `nested_exception`, an exception of unspecified type that is publicly
351
- derived from both `U` and `nested_exception` and constructed from
 
352
  `std::forward<T>(t)`, otherwise `std::forward<T>(t)`.
353
 
354
  ``` cpp
355
  template <class E> void rethrow_if_nested(const E& e);
356
  ```
357
 
358
- *Effects:* If the dynamic type of `e` is publicly and unambiguously
359
- derived from `nested_exception`, calls `dynamic_cast<const`
360
- `nested_exception&>(e).rethrow_nested()`.
 
 
 
 
 
361
 
 
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
 
14
+ using terminate_handler = void (*)();
 
 
 
 
 
15
  terminate_handler get_terminate() noexcept;
16
  terminate_handler set_terminate(terminate_handler f) noexcept;
17
  [[noreturn]] void terminate() noexcept;
18
 
19
+ int uncaught_exceptions() noexcept;
20
 
21
+ using exception_ptr = unspecified;
22
 
23
  exception_ptr current_exception() noexcept;
24
  [[noreturn]] void rethrow_exception(exception_ptr p);
25
  template<class E> exception_ptr make_exception_ptr(E e) noexcept;
26
 
 
68
  exception& operator=(const exception& rhs) noexcept;
69
  ```
70
 
71
  *Effects:* Copies an `exception` object.
72
 
73
+ *Postconditions:* If `*this` and `rhs` both have dynamic type
74
+ `exception` then the value of the expression
75
  `strcmp(what(), rhs.what())` shall equal 0.
76
 
77
  ``` cpp
78
  virtual ~exception();
79
  ```
 
100
  class bad_exception : public exception {
101
  public:
102
  bad_exception() noexcept;
103
  bad_exception(const bad_exception&) noexcept;
104
  bad_exception& operator=(const bad_exception&) noexcept;
105
+ const char* what() const noexcept override;
106
  };
107
  }
108
  ```
109
 
110
+ The class `bad_exception` defines the type of the object referenced by
111
+ the `exception_ptr` returned from a call to `current_exception` (
112
+ [[propagation]]) when the currently active exception object fails to
113
+ copy.
114
 
115
  ``` cpp
116
  bad_exception() noexcept;
117
  ```
118
 
119
  *Effects:* Constructs an object of class `bad_exception`.
120
 
 
 
 
121
  ``` cpp
122
  bad_exception(const bad_exception&) noexcept;
123
  bad_exception& operator=(const bad_exception&) noexcept;
124
  ```
125
 
126
  *Effects:* Copies an object of class `bad_exception`.
127
 
128
  ``` cpp
129
+ const char* what() const noexcept override;
130
  ```
131
 
132
  *Returns:* An *implementation-defined* NTBS.
133
 
134
  *Remarks:* The message may be a null-terminated multibyte
 
138
  ### Abnormal termination <a id="exception.terminate">[[exception.terminate]]</a>
139
 
140
  #### Type `terminate_handler` <a id="terminate.handler">[[terminate.handler]]</a>
141
 
142
  ``` cpp
143
+ using terminate_handler = void (*)();
144
  ```
145
 
146
  The type of a *handler function* to be called by `std::terminate()` when
147
  terminating exception processing.
148
 
 
170
 
171
  ``` cpp
172
  terminate_handler get_terminate() noexcept;
173
  ```
174
 
175
+ *Returns:* The current `terminate_handler`.
176
+
177
+ [*Note 1*: This may be a null pointer value. — *end note*]
178
 
179
  #### `terminate` <a id="terminate">[[terminate]]</a>
180
 
181
  ``` cpp
182
  [[noreturn]] void terminate() noexcept;
183
  ```
184
 
185
  *Remarks:* Called by the implementation when exception handling must be
186
+ abandoned for any of several reasons ([[except.terminate]]). May also
187
+ be called directly by the program.
 
188
 
189
+ *Effects:* Calls a `terminate_handler` function. It is unspecified which
190
+ `terminate_handler` function will be called if an exception is active
191
+ during a call to `set_terminate`. Otherwise calls the current
192
+ `terminate_handler` function.
193
 
194
+ [*Note 1*: A default `terminate_handler` is always considered a
195
+ callable handler in this context. — *end note*]
196
+
197
+ ### `uncaught_exceptions` <a id="uncaught.exceptions">[[uncaught.exceptions]]</a>
198
 
199
  ``` cpp
200
+ int uncaught_exceptions() noexcept;
201
  ```
202
 
203
+ *Returns:* The number of uncaught exceptions ([[except.uncaught]]).
 
 
 
 
204
 
205
+ *Remarks:* When `uncaught_exceptions() > 0`, throwing an exception can
206
+ result in a call of
207
  `std::terminate()` ([[except.terminate]]).
208
 
209
  ### Exception propagation <a id="propagation">[[propagation]]</a>
210
 
211
  ``` cpp
212
+ using exception_ptr = unspecified;
213
  ```
214
 
215
+ The type `exception_ptr` can be used to refer to an exception object.
216
 
217
  `exception_ptr` shall satisfy the requirements of
218
  `NullablePointer` ([[nullablepointer.requirements]]).
219
 
220
  Two non-null values of type `exception_ptr` are equivalent and compare
 
224
  the type.
225
 
226
  `exception_ptr` shall not be implicitly convertible to any arithmetic,
227
  enumeration, or pointer type.
228
 
229
+ [*Note 1*: An implementation might use a reference-counted smart
230
+ pointer as `exception_ptr`. — *end note*]
231
 
232
  For purposes of determining the presence of a data race, operations on
233
  `exception_ptr` objects shall access and modify only the `exception_ptr`
234
  objects themselves and not the exceptions they refer to. Use of
235
  `rethrow_exception` on `exception_ptr` objects that refer to the same
236
+ exception object shall not introduce a data race.
237
+
238
+ [*Note 2*: If `rethrow_exception` rethrows the same exception object
239
+ (rather than a copy), concurrent access to that rethrown exception
240
+ object may introduce a data race. Changes in the number of
241
+ `exception_ptr` objects that refer to a particular exception do not
242
+ introduce a data race. — *end note*]
243
 
244
  ``` cpp
245
  exception_ptr current_exception() noexcept;
246
  ```
247
 
 
251
  being handled. The referenced object shall remain valid at least as long
252
  as there is an `exception_ptr` object that refers to it. If the function
253
  needs to allocate memory and the attempt fails, it returns an
254
  `exception_ptr` object that refers to an instance of `bad_alloc`. It is
255
  unspecified whether the return values of two successive calls to
256
+ `current_exception` refer to the same exception object.
257
+
258
+ [*Note 3*: That is, it is unspecified whether `current_exception`
259
+ creates a new copy each time it is called. — *end note*]
260
+
261
+ If the attempt to copy the current exception object throws an exception,
262
+ the function returns an `exception_ptr` object that refers to the thrown
263
+ exception or, if this is not possible, to an instance of
264
+ `bad_exception`.
265
+
266
+ [*Note 4*: The copy constructor of the thrown exception may also fail,
267
+ so the implementation is allowed to substitute a `bad_exception` object
268
+ to avoid infinite recursion. — *end note*]
269
 
270
  ``` cpp
271
  [[noreturn]] void rethrow_exception(exception_ptr p);
272
  ```
273
 
274
  *Requires:* `p` shall not be a null pointer.
275
 
276
+ *Throws:* The exception object to which `p` refers.
277
 
278
  ``` cpp
279
  template<class E> exception_ptr make_exception_ptr(E e) noexcept;
280
  ```
281
 
282
  *Effects:* Creates an `exception_ptr` object that refers to a copy of
283
+ `e`, as if:
284
 
285
  ``` cpp
286
  try {
287
  throw e;
288
  } catch(...) {
289
  return current_exception();
290
  }
291
  ```
292
 
293
+ [*Note 5*: This function is provided for convenience and efficiency
294
+ reasons. — *end note*]
295
 
296
  ### `nested_exception` <a id="except.nested">[[except.nested]]</a>
297
 
298
  ``` cpp
299
  namespace std {
 
316
 
317
  The class `nested_exception` is designed for use as a mixin through
318
  multiple inheritance. It captures the currently handled exception and
319
  stores it for later use.
320
 
321
+ [*Note 1*: `nested_exception` has a virtual destructor to make it a
322
+ polymorphic class. Its presence can be tested for with
323
+ `dynamic_cast`. — *end note*]
324
 
325
  ``` cpp
326
  nested_exception() noexcept;
327
  ```
328
 
 
346
 
347
  ``` cpp
348
  template <class T> [[noreturn]] void throw_with_nested(T&& t);
349
  ```
350
 
351
+ Let `U` be `decay_t<T>`.
352
 
353
  *Requires:* `U` shall be `CopyConstructible`.
354
 
355
+ *Throws:* If
356
+ `is_class_v<U> && !is_final_v<U> && !is_base_of_v<nested_exception, U>`
357
+ is `true`, an exception of unspecified type that is publicly derived
358
+ from both `U` and `nested_exception` and constructed from
359
  `std::forward<T>(t)`, otherwise `std::forward<T>(t)`.
360
 
361
  ``` cpp
362
  template <class E> void rethrow_if_nested(const E& e);
363
  ```
364
 
365
+ *Effects:* If `E` is not a polymorphic class type, or if
366
+ `nested_exception` is an inaccessible or ambiguous base class of `E`,
367
+ there is no effect. Otherwise, performs:
368
+
369
+ ``` cpp
370
+ if (auto p = dynamic_cast<const nested_exception*>(addressof(e)))
371
+ p->rethrow_nested();
372
+ ```
373