Title
current_exception wording unclear about exception type
Status
cd1
Section
[propagation]
Submitter
Beman Dawes

Created on 2008-04-20.00:00:00 last changed 164 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

After [propagation] , paragraph 7, add the indicated text:

exception_ptr current_exception();

Returns: exception_ptr object that refers to the currently handled exception ([except.handle]) or a copy of the currently handled exception, or a null exception_ptr object if no exception is being handled. If the function needs to allocate memory and the attempt fails, it returns an exception_ptr object that refers to an instance of bad_alloc. It is unspecified whether the return values of two successive calls to current_exception refer to the same exception object. [Note: that is, it is unspecified whether current_exception creates a new copy each time it is called. -- end note]

Throws: nothing.

Date: 2010-10-21.18:28:33

[ 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 [except.handle]/8; this is the exception that throw; would rethrow, see [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 ([except.throw]/7) would rethrow. --end note] is also an option.

Date: 2008-04-20.00:00:00

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.

History
Date User Action Args
2010-10-21 18:28:33adminsetmessages: + msg3958
2010-10-21 18:28:33adminsetmessages: + msg3957
2008-04-20 00:00:00admincreate