Skip to content

Commit d7bceb6

Browse files
author
Stefanus Du Toit
committed
CWG1431 DR
"There are a number of places in the Standard that appear to assume that exceptions are only thrown by throw-expressions. Various other constructs, such as dynamic_casts, typeid, new-expressions, etc., can also throw exceptions, so a more general term should be coined and applied in place of throw-expression wherever necessary."
1 parent 90ba16f commit d7bceb6

4 files changed

Lines changed: 36 additions & 50 deletions

File tree

source/basic.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2933,8 +2933,8 @@
29332933
\grammarterm{exception-specification}~(\ref{except.spec})
29342934
fails to allocate storage, it shall return a null pointer. Any other
29352935
allocation function that fails to allocate storage shall indicate
2936-
failure only by throwing an exception of a type that would match a
2937-
handler~(\ref{except.handle}) of type
2936+
failure only by throwing an exception~(\ref{except.throw}) of a type
2937+
that would match a handler~(\ref{except.handle}) of type
29382938
\tcode{std::bad_alloc}~(\ref{bad.alloc}).
29392939

29402940
\pnum

source/exceptions.tex

Lines changed: 30 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
Exception handling provides a way of transferring control and information
1212
from a point in the execution of a thread to an exception handler
1313
associated with a point previously passed by the execution.
14-
A handler will be invoked only by a
15-
\grammarterm{throw-expression}
16-
invoked in code executed in the handler's try block
14+
A handler will be invoked only by throwing an exception
15+
in code executed in the handler's try block
1716
or in functions called from the handler's try block .
1817

1918
\indextext{\idxcode{try}}%
@@ -65,9 +64,7 @@
6564
\indextext{try block|see{exception handling, try block}}%
6665
\indextext{handler|see{exception handling, handler}}%
6766
A \grammarterm{try-block} is a \grammarterm{statement} (Clause~\ref{stmt.stmt}).
68-
A \grammarterm{throw-expression} is of type \tcode{void}. Code that executes a
69-
\grammarterm{throw-expression} is said to ``throw an exception;'' code that
70-
subsequently gets control is called a ``handler.'' \enternote Within this Clause
67+
A \grammarterm{throw-expression} is of type \tcode{void}. \enternote Within this Clause
7168
``try block'' is taken to mean both \grammarterm{try-block} and
7269
\grammarterm{function-try-block}. \exitnote
7370

@@ -199,6 +196,15 @@
199196

200197
\pnum
201198
Throwing an exception transfers control to a handler.
199+
\enternote
200+
An exception can be thrown from one of the following contexts:
201+
\grammarterm{throw-expression} (see below), allocation
202+
functions~(\ref{basic.stc.dynamic.allocation}),
203+
\tcode{dynamic_cast}~(\ref{expr.dynamic.cast}),
204+
\tcode{typeid}~(\ref{expr.typeid}),
205+
\grammarterm{new-expression}~(\ref{expr.new}), and standard library
206+
functions~(\ref{structure.specifications}).
207+
\exitnote
202208
An object is passed and the type of that object determines which handlers
203209
can catch it.
204210
\enterexample
@@ -255,38 +261,23 @@
255261
keyword was most recently entered by the thread of control and not yet exited.
256262

257263
\pnum
258-
A
259-
\grammarterm{throw-expression}
260-
copy-initializes~(\ref{dcl.init}) a temporary object,
264+
Throwing an exception
265+
copy-initializes~(\ref{dcl.init}, \ref{class.copy}) a temporary object,
261266
called the
262-
\indextext{exception handling!exception object}\term{exception object},
263-
the type of which
264-
is determined by removing any top-level
265-
\grammarterm{cv-qualifier}{s}
266-
from the static type of the operand of
267-
\tcode{throw}
268-
and adjusting the type from ``array of
269-
\tcode{T}''
270-
or ``function returning
271-
\tcode{T}''
272-
to ``pointer to
273-
\tcode{T}''
274-
or ``pointer to function
275-
returning
276-
\tcode{T}'',
277-
respectively.
267+
\indextext{exception handling!exception object}\term{exception object}.
278268
The temporary is an lvalue and is used to initialize the
279269
variable named in the matching
280270
\term{handler}~(\ref{except.handle}).
281271
If the type of the exception object would
282272
be an incomplete type or a pointer to an incomplete
283273
type other than (possibly cv-qualified)
284274
\tcode{void} the program is ill-formed.
285-
Except for these restrictions and the restrictions on type matching mentioned
286-
in~\ref{except.handle}, the operand of
287-
\tcode{throw}
288-
is treated exactly as a function argument in a call~(\ref{expr.call}) or the operand
289-
of a return statement.
275+
Evaluating a \grammarterm{throw-expression} with an operand throws an
276+
exception; the type of the exception object is determined by removing
277+
any top-level \grammarterm{cv-qualifiers} from the static type of the
278+
operand and adjusting the type from ``array of \tcode{T}'' or ``function
279+
returning \tcode{T}'' to ``pointer to \tcode{T}'' or ``pointer to function returning
280+
\tcode{T},'' respectively.
290281

291282
\pnum
292283
\indextext{exception handling!memory}%
@@ -308,7 +299,7 @@
308299
The implementation may then
309300
deallocate the memory for the exception object; any such deallocation
310301
is done in an unspecified way.
311-
\enternote an exception thrown by a \grammarterm{throw-expression} does not
302+
\enternote a thrown exception does not
312303
propagate to other threads unless caught, stored, and rethrown using
313304
appropriate library functions; see~\ref{propagation} and~\ref{futures}. \exitnote
314305

@@ -358,8 +349,8 @@
358349
A
359350
\grammarterm{throw-expression}
360351
with no operand rethrows the currently handled exception~(\ref{except.handle}).
361-
The exception is reactivated with the existing temporary;
362-
no new temporary exception object is created.
352+
The exception is reactivated with the existing exception object;
353+
no new exception object is created.
363354
The exception
364355
is no longer considered to be caught; therefore, the value
365356
of
@@ -398,8 +389,7 @@
398389
\indextext{destructor!exception~handling|see{exception handling, constructors and destructors}}
399390

400391
\pnum
401-
As control passes from a
402-
\grammarterm{throw-expression}
392+
As control passes from the point where an exception is thrown
403393
to a handler,
404394
destructors are invoked for all automatic objects constructed since the
405395
try block was entered.
@@ -427,8 +417,7 @@
427417
\pnum
428418
\indextext{unwinding!stack}%
429419
The process of calling destructors for automatic objects constructed on the
430-
path from a try block to a
431-
\grammarterm{throw-expression}
420+
path from a try block to the point where an exception is thrown
432421
is called
433422
``\term{stack unwinding}.''
434423
If a destructor called during stack unwinding exits with an exception,
@@ -712,15 +701,11 @@
712701
within the handler.
713702

714703
\pnum
715-
When the handler declares a non-constant object,
716-
any changes to that object will not affect the temporary object
717-
that was initialized by execution of the
718-
\grammarterm{throw-expression}.
719-
When the handler declares a reference to a non-constant object,
704+
When the handler declares an object,
705+
any changes to that object will not affect the exception object.
706+
When the handler declares a reference to an object,
720707
any changes to the referenced object are changes to the
721-
temporary object initialized when the
722-
\grammarterm{throw-expression}
723-
was executed and will have effect should that object be rethrown.%
708+
exception object and will have effect should that object be rethrown.%
724709
\indextext{exception handling!handler!match|)}%
725710
\indextext{exception handling!handler|)}
726711

source/expressions.tex

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,7 +1547,8 @@
15471547
\pnum
15481548
The value of a failed cast to pointer type is the null pointer value of
15491549
the required result type. A failed cast to reference type throws
1550-
\tcode{std::bad_cast}~(\ref{bad.cast}).
1550+
an exception~(\ref{except.throw}) of a type that would match a
1551+
handler~(\ref{except.handle}) of type \tcode{std::bad_cast}~(\ref{bad.cast}).
15511552

15521553
\indextext{\idxcode{bad_cast}}%
15531554
\indexlibrary{\idxcode{bad_cast}}%
@@ -2661,7 +2662,7 @@
26612662
which the number of \grammarterm{initializer-clause}{s} exceeds the number of
26622663
elements to initialize,
26632664
no storage is obtained and the
2664-
\grammarterm{new-expression} terminates by throwing an exception of a type that would
2665+
\grammarterm{new-expression} throws an exception~(\ref{except.throw}) of a type that would
26652666
match a handler~(\ref{except.handle}) of type
26662667
\tcode{std::bad_array_new_length}~(\ref{new.badlength}).
26672668

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2755,7 +2755,7 @@
27552755
\remarks
27562756
Called by the implementation when exception
27572757
handling must be abandoned for any of several reasons~(\ref{except.terminate}),
2758-
in effect immediately after evaluating the \grammarterm{throw-expression}~(\ref{terminate.handler}).
2758+
in effect immediately after throwing the exception.
27592759
May also be called directly by the program.
27602760

27612761
\pnum

0 commit comments

Comments
 (0)