<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Issue 1130: copy_exception name misleading</title>
<meta property="og:title" content="Issue 1130: copy_exception name misleading">
<meta property="og:description" content="C++ library issue. Status: C++11">
<meta property="og:url" content="https://cplusplus.github.io/LWG/issue1130.html">
<meta property="og:type" content="website">
<meta property="og:image" content="http://cplusplus.github.io/LWG/images/cpp_logo.png">
<meta property="og:image:alt" content="C++ logo">
<style>
  p {text-align:justify}
  li {text-align:justify}
  pre code.backtick::before { content: "`" }
  pre code.backtick::after { content: "`" }
  blockquote.note
  {
    background-color:#E0E0E0;
    padding-left: 15px;
    padding-right: 15px;
    padding-top: 1px;
    padding-bottom: 1px;
  }
  ins {background-color:#A0FFA0}
  del {background-color:#FFA0A0}
  table.issues-index { border: 1px solid; border-collapse: collapse; }
  table.issues-index th { text-align: center; padding: 4px; border: 1px solid; }
  table.issues-index td { padding: 4px; border: 1px solid; }
  table.issues-index td:nth-child(1) { text-align: right; }
  table.issues-index td:nth-child(2) { text-align: left; }
  table.issues-index td:nth-child(3) { text-align: left; }
  table.issues-index td:nth-child(4) { text-align: left; }
  table.issues-index td:nth-child(5) { text-align: center; }
  table.issues-index td:nth-child(6) { text-align: center; }
  table.issues-index td:nth-child(7) { text-align: left; }
  table.issues-index td:nth-child(5) span.no-pr { color: red; }
  @media (prefers-color-scheme: dark) {
     html {
        color: #ddd;
        background-color: black;
     }
     ins {
        background-color: #225522
     }
     del {
        background-color: #662222
     }
     a {
        color: #6af
     }
     a:visited {
        color: #6af
     }
     blockquote.note
     {
        background-color: rgba(255, 255, 255, .10)
     }
  }
</style>
</head>
<body>
<hr>
<p><em>This page is a snapshot from the LWG issues list, see the <a href="lwg-active.html">Library Active Issues List</a> for more information and the meaning of <a href="lwg-active.html#C++11">C++11</a> status.</em></p>
<h3 id="1130"><a href="lwg-defects.html#1130">1130</a>. <code>copy_exception</code> name misleading</h3>
<p><b>Section:</b> 17.9.7 <a href="https://wg21.link/propagation">[propagation]</a> <b>Status:</b> <a href="lwg-active.html#C++11">C++11</a>
 <b>Submitter:</b> Peter Dimov <b>Opened:</b> 2009-05-13 <b>Last modified:</b> 2016-01-28</p>
<p><b>Priority: </b>Not Prioritized
</p>
<p><b>View all other</b> <a href="lwg-index.html#propagation">issues</a> in [propagation].</p>
<p><b>View all issues with</b> <a href="lwg-status.html#C++11">C++11</a> status.</p>
<p><b>Discussion:</b></p>
<p>
The naming of <code>std::copy_exception</code> misleads almost everyone
(experts included!) to think that it is the function that copies an
<code>exception_ptr</code>:
</p>

<blockquote><pre>
exception_ptr p1 = current_exception();
exception_ptr p2 = copy_exception( p1 );
</pre></blockquote>

<p>
But this is not at all what it does. The above actually creates an
<code>exception_ptr p2</code> that contains a copy of <code>p1</code>, not of
the exception to which <code>p1</code> refers!
</p>
<p>
This is, of course, all my fault; in my defence, I used <code>copy_exception</code>
because I was unable to think of a better name.
</p>
<p>
But I believe that, based on what we've seen so far, <em>any</em> other name would be better.
</p>
<p>
Therefore, I propose <code>copy_exception</code> to be renamed to
<code>create_exception</code>:
</p>

<blockquote><pre>
template&lt;class E&gt; exception_ptr create_exception(E e);
</pre></blockquote>

<p>
with the following explanatory paragraph after it:
</p>

<blockquote><p>
Creates an <code>exception_ptr</code> that refers to a copy of <code>e</code>.
</p></blockquote>

<p><i>[
2009-05-13 Daniel adds:
]</i></p>


<blockquote>
<p>
What about
</p>
<blockquote><pre>
make_exception_ptr
</pre></blockquote>
<p>
in similarity to <code>make_pair</code> and <code>make_tuple</code>, <code>make_error_code</code> and
<code>make_error_condition</code>, or <code>make_shared</code>? Or, if a stronger symmetry to
<code>current_exception</code> is preferred:
</p>

<blockquote><pre>
make_exception
</pre></blockquote>
<p>
We have not a single <code>create_*</code> function in the library, it was always
<code>make_*</code> used.
</p>
</blockquote>

<p><i>[
2009-05-13 Peter adds:
]</i></p>


<blockquote><p>
<code>make_exception_ptr</code> works for me.
</p></blockquote>

<p><i>[
2009-06-02 Thomas J. Gritzan adds:
]</i></p>


<blockquote>
<p>
To avoid surprises and unwanted recursion, how about making a call to
<code>std::make_exception_ptr</code> with an <code>exception_ptr</code> illegal?
</p>
<p>
It might work like this:
</p>
<blockquote><pre>
template&lt;class E&gt;
exception_ptr make_exception_ptr(E e);
template&lt;&gt;
exception_ptr make_exception_ptr&lt;exception_ptr&gt;(exception_ptr e) = delete;
</pre></blockquote>
</blockquote>

<p><i>[
2009 Santa Cruz:
]</i></p>


<blockquote><p>
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.
</p></blockquote>

<p><i>[
2009-11-16 Jonathan Wakely adds:
]</i></p>


<blockquote><p>
GCC 4.4 shipped with <code>copy_exception</code> 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.
</p></blockquote>

<p><i>[
2009-11-16 Peter adopts wording supplied by Daniel.
]</i></p>


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



<p id="res-1130"><b>Proposed resolution:</b></p>
<ol>
<li>
<p>
Change 17.9 <a href="https://wg21.link/support.exception">[support.exception]</a>/1, header <code>&lt;exception&gt;</code>
synopsis as indicated:
</p>

<blockquote><pre>
exception_ptr current_exception();
void rethrow_exception [[noreturn]] (exception_ptr p);
template&lt;class E&gt; exception_ptr <del>copy_exception</del><ins>make_exception_ptr</ins>(E e);
</pre></blockquote>
</li>

<li>
<p>
Change 17.9.7 <a href="https://wg21.link/propagation">[propagation]</a>:
</p>

<blockquote>
<pre>
template&lt;class E&gt; exception_ptr <del>copy_exception</del><ins>make_exception_ptr</ins>(E e);
</pre>

<blockquote>
<p>
-11- <i>Effects:</i> <ins>Creates an <code>exception_ptr</code> that refers
to a copy of <code>e</code>,</ins> as if
</p>

<blockquote><pre>
try {
  throw e;
} catch(...) {
  return current_exception();
}
</pre></blockquote>

<p>...</p>
</blockquote>

</blockquote>
</li>

<li>
<p>
Change 32.10.6 <a href="https://wg21.link/futures.promise">[futures.promise]</a>/7 as indicated:
</p>

<blockquote><p>
<i>Effects:</i> if the associated state of <code>*this</code> is not ready, stores an exception
object of type <code>future_error</code> with an error code of <code>broken_promise</code> as if by
<code>this-&gt;set_exception(<del>copy_exception</del><ins>make_exception_ptr</ins>(
future_error(future_errc::broken_promise))</code>.  Destroys ...
</p></blockquote>
</li>
</ol>






</body>
</html>
