Section: 17.9.7 [propagation] Status: CD1 Submitter: Beman Dawes Opened: 2008-04-20 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [propagation].
View all issues with CD1 status.
Discussion:
Consider this code:
exception_ptr xp;try {do_something(); } catch (const runtime_error& ) {xp = current_exception();} ... rethrow_exception(xp);
Say do_something()
throws an exception object of type
range_error
. What is the type of the exception object thrown by
rethrow_exception(xp)
above? It must have a type of range_error
;
if it were of type runtime_error
it still isn't possible to
propagate an exception and the exception_ptr/current_exception/rethrow_exception
machinery serves no useful purpose.
Unfortunately, the current wording does not explicitly say that. Different people read the current wording and come to different conclusions. While it may be possible to deduce the correct type from the current wording, it would be much clearer to come right out and explicitly say what the type of the referred to exception is.
[ Peter adds: ]
I don't like the proposed resolution of 829. The normative text is unambiguous that the
exception_ptr
refers to the currently handled exception. This term has a standard meaning, see 14.4 [except.handle]/8; this is the exception thatthrow;
would rethrow, see 14.2 [except.throw]/7.A better way to address this is to simply add the non-normative example in question as a clarification. The term currently handled exception should be italicized and cross-referenced. A [Note: the currently handled exception is the exception that a throw expression without an operand (14.2 [except.throw]/7) would rethrow. --end note] is also an option.
Proposed resolution:
After 17.9.7 [propagation] , paragraph 7, add the indicated text:
exception_ptr current_exception();Returns:
exception_ptr
object that refers to the currently handled exception (14.4 [except.handle]) or a copy of the currently handled exception, or a nullexception_ptr
object if no exception is being handled. If the function needs to allocate memory and the attempt fails, it returns anexception_ptr
object that refers to an instance ofbad_alloc
. It is unspecified whether the return values of two successive calls tocurrent_exception
refer to the same exception object. [Note: that is, it is unspecified whethercurrent_exception
creates a new copy each time it is called. -- end note]Throws: nothing.