Title
copy_exception name misleading
Status
c++11
Section
[propagation]
Submitter
Peter Dimov

Created on 2009-05-13.00:00:00 last changed 161 months ago

Messages

Date: 2010-10-21.18:28:33

Proposed resolution:

  1. Change [support.exception]/1, header <exception> synopsis as indicated:

    exception_ptr current_exception();
    void rethrow_exception [[noreturn]] (exception_ptr p);
    template<class E> exception_ptr copy_exceptionmake_exception_ptr(E e);
    
  2. Change [propagation]:

    template<class E> exception_ptr copy_exceptionmake_exception_ptr(E e);
    

    -11- Effects: Creates an exception_ptr that refers to a copy of e, as if

    try {
      throw e;
    } catch(...) {
      return current_exception();
    }
    

    ...

  3. Change [futures.promise]/7 as indicated:

    Effects: if the associated state of *this is not ready, stores an exception object of type future_error with an error code of broken_promise as if by this->set_exception(copy_exceptionmake_exception_ptr( future_error(future_errc::broken_promise)). Destroys ...

Date: 2009-11-16.00:00:00

[ 2009-11-16 Moved to Tentatively Ready after 5 positive votes on c++std-lib. ]

Date: 2009-11-16.00:00:00

[ 2009-11-16 Peter adopts wording supplied by Daniel. ]

Date: 2009-11-16.00:00:00

[ 2009-11-16 Jonathan Wakely adds: ]

GCC 4.4 shipped with copy_exception but we could certainly keep that symbol in the library (but not the headers) so it can still be found by any apps foolishly relying on the experimental C++0x mode being ABI stable.

Date: 2010-10-21.18:28:33

[ 2009 Santa Cruz: ]

Move to Review for the time being. The subgroup thinks this is a good idea, but doesn't want to break compatibility unnecessarily if someone is already shipping this. Let's talk to Benjamin and PJP tomorrow to make sure neither objects.

Date: 2009-06-02.00:00:00

[ 2009-06-02 Thomas J. Gritzan adds: ]

To avoid surprises and unwanted recursion, how about making a call to std::make_exception_ptr with an exception_ptr illegal?

It might work like this:

template<class E>
exception_ptr make_exception_ptr(E e);
template<>
exception_ptr make_exception_ptr<exception_ptr>(exception_ptr e) = delete;
Date: 2009-05-13.00:00:00

[ 2009-05-13 Peter adds: ]

make_exception_ptr works for me.

Date: 2009-05-13.00:00:00

[ 2009-05-13 Daniel adds: ]

What about

make_exception_ptr

in similarity to make_pair and make_tuple, make_error_code and make_error_condition, or make_shared? Or, if a stronger symmetry to current_exception is preferred:

make_exception

We have not a single create_* function in the library, it was always make_* used.

Date: 2009-05-13.00:00:00

The naming of std::copy_exception misleads almost everyone (experts included!) to think that it is the function that copies an exception_ptr:

exception_ptr p1 = current_exception();
exception_ptr p2 = copy_exception( p1 );

But this is not at all what it does. The above actually creates an exception_ptr p2 that contains a copy of p1, not of the exception to which p1 refers!

This is, of course, all my fault; in my defence, I used copy_exception because I was unable to think of a better name.

But I believe that, based on what we've seen so far, any other name would be better.

Therefore, I propose copy_exception to be renamed to create_exception:

template<class E> exception_ptr create_exception(E e);

with the following explanatory paragraph after it:

Creates an exception_ptr that refers to a copy of e.

History
Date User Action Args
2011-08-23 20:07:26adminsetstatus: wp -> c++11
2010-10-21 18:28:33adminsetmessages: + msg858
2010-10-21 18:28:33adminsetmessages: + msg857
2010-10-21 18:28:33adminsetmessages: + msg856
2010-10-21 18:28:33adminsetmessages: + msg855
2010-10-21 18:28:33adminsetmessages: + msg854
2010-10-21 18:28:33adminsetmessages: + msg853
2010-10-21 18:28:33adminsetmessages: + msg852
2010-10-21 18:28:33adminsetmessages: + msg851
2009-05-13 00:00:00admincreate