<html>
	<head>
		<title>Language Support for Transporting Exceptions between Threads</title>
		<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
		<meta http-equiv="Content-Language" content="en-us">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	</head>
	<body bgColor="#ffffff">
		<ADDRESS>Document number: N2179=07-0039</ADDRESS>
		<ADDRESS>Programming Language C++, Evolution Subgroup</ADDRESS>
		<ADDRESS>&nbsp;</ADDRESS>
		<ADDRESS>Peter Dimov, &lt;<A href="mailto:pdimov@pdimov.com">pdimov@pdimov.com</A>&gt;</ADDRESS>
		<ADDRESS>&nbsp;</ADDRESS>
		<ADDRESS>2007-03-03</ADDRESS>
		<h1>Language Support for Transporting Exceptions between Threads</h1>
		<h2>I. Overview</h2>
		<p>
            This document proposes a minimal and complete addition to the C++ standard that
            enables a library to move an exception from one thread to another. The interface
            is essentially a slight reformulation of Option 2 suggested in N2107, <em>Exception
                Propagation across Threads</em>, by Jens Maurer and Alisdair Meredith.</p>
		<h2>II. Proposed Text</h2>
		<p>
            Add to the synopsis of <em>&lt;exception&gt;</em> the following:</p>
<pre>namespace std {

    typedef <em>unspecified</em> exception_ptr;

    exception_ptr current_exception();
    void rethrow_exception( exception_ptr p );

    template&lt; class E &gt; exception_ptr copy_exception( E e );

}
</pre>
        <p>
            Add another section, <em>Exception Propagation [propagation]</em>, after <em>[uncaught]</em>
            with
            the following contents:</p>
        <pre>typedef <em>unspecified</em> exception_ptr;</pre>
        <p>
            The type <em>exception_ptr</em> can be used to refer to an exception.</p>
        <p>
            <em>exception_ptr</em> shall be DefaultConstructible, CopyConstructible, Assignable and
            EqualityComparable. <em>exception_ptr</em>'s operations do not throw.</p>
        <p>
            Two instances of <em>exception_ptr</em> are equivalent and compare equal if and
            only if they refer to the same exception.</p>
        <p>
            The default constructor of <em>exception_ptr</em> produces the null value of the
            type. The null value is equivalent only to itself.</p>
        <p>
            <em>exception_ptr</em> can be compared for equality with a null pointer constant
            or assigned a null pointer constant.
            The effect shall be as if <code>exception_ptr()</code> was used in place of the null pointer constant.</p>
        <p>
            [<em>Note:</em> An implementation might use a reference-counted smart pointer as
            <em>exception_ptr</em>.]</p>
        <pre>exception_ptr current_exception();</pre>
        <p>
            <em>Returns:</em> An <em>exception_ptr</em> that refers to the currently handled
            exception or a copy of the currently handled exception, or a null <em>exception_ptr</em> if no exception is being handled. If the function needs to allocate memory and the
            attempt fails, it returns an <em>exception_ptr</em> that refers to an instance of
            <em>bad_alloc</em>. It is unspecified whether the return values of
            two successive calls to <em>current_exception</em> refer to the same exception.</p>
        <p>
            [<em>Note:</em> that is, it is unspecified whether <em>current_exception</em> creates
            a new copy each time it is called.]</p>
        <p>
            <em>Throws:</em> nothing.</p>
        <pre>void rethrow_exception( exception_ptr p );</pre>
        <p>
            <em>Requires:</em> <em>p</em> shall not be null.</p>
        <p>
            <em>Throws:</em> the exception to which <em>p</em> refers.</p>
        <pre>template&lt; class E &gt; exception_ptr copy_exception( E e );</pre>
        <p>
            <em>Effects:</em> as if <code>try { throw e; } catch( ... ) { return current_exeption(); }</code>.</p>
        <p>
            [<em>Note:</em> This function is provided for convenience and efficiency reasons.]</p>
		<p><em>--end</em></p>
	</body>
</html>
