1130. copy_exception name misleading

Section: 21.8.6 [propagation] Status: C++11 Submitter: Peter Dimov Opened: 2009-05-13 Last modified: 2016-02-10

Priority: Not Prioritized

View all other issues in [propagation].

View all issues with C++11 status.

Discussion:

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.

[ 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.

[ 2009-05-13 Peter adds: ]

make_exception_ptr works for me.

[ 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;

[ 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.

[ 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.

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

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

Proposed resolution:

  1. Change 21.8 [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 21.8.6 [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 33.6.6 [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 ...