<HTML>
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<TITLE>
    CWG Issue 1431</TITLE>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<STYLE TYPE="text/css">
  INS { text-decoration:none; font-weight:bold; background-color:#A0FFA0 }
  .INS { text-decoration:none; background-color:#D0FFD0 }
  DEL { text-decoration:line-through; background-color:#FFA0A0 }
  .DEL { text-decoration:line-through; background-color: #FFD0D0 }
  @media (prefers-color-scheme: dark) {
    HTML { background-color:#202020; color:#f0f0f0; }
    A { color:#5bc0ff; }
    A:visited { color:#c6a8ff; }
    A:hover, a:focus { color:#afd7ff; }
    INS { background-color:#033a16; color:#aff5b4; }
    .INS { background-color: #033a16; }
    DEL { background-color:#67060c; color:#ffdcd7; }
    .DEL { background-color:#67060c; }
  }
  SPAN.cmnt { font-family:Times; font-style:italic }
</STYLE>
</HEAD>
<BODY>
<P><EM>This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
  Core Issues List revision 118b.
  See http://www.open-std.org/jtc1/sc22/wg21/ for the official
  list.</EM></P>
<P>2025-09-28</P>
<HR>
<A NAME="1431"></A><H4>1431.
  
Exceptions from other than <I>throw-expression</I>s
</H4>
<B>Section: </B>Clause 14&#160; [<A href="https://wg21.link/except">except</A>]
 &#160;&#160;&#160;

 <B>Status: </B>CD3
 &#160;&#160;&#160;

 <B>Submitter: </B>Nikolay Ivchenkov
 &#160;&#160;&#160;

 <B>Date: </B>2011-12-16<BR>


<P>[Moved to DR at the October, 2012 meeting.]</P>



<P>There are a number of places in the Standard that appear to
assume that exceptions are only thrown by <I>throw-expression</I>s.
Various other constructs, such as <TT>dynamic_cast</TT>s,
<TT>typeid</TT>, <I>new-expression</I>s, etc., can also throw
exceptions, so a more general term should be coined and applied
in place of <I>throw-expression</I> wherever necessary.</P>

<P><B>Proposed resolution (February, 2012):</B></P>

<OL>
<LI><P>Change 6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation#3">basic.stc.dynamic.allocation</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

...Any other allocation function that fails to allocate storage shall
indicate failure only by throwing an exception <INS>(14.2 [<A href="https://wg21.link/except.throw">except.throw</A>])</INS> of a type that would match a handler (14.4 [<A href="https://wg21.link/except.handle">except.handle</A>]) of type <TT>std::bad_alloc</TT> (17.6.4.1 [<A href="https://wg21.link/bad.alloc">bad.alloc</A>]).

</BLOCKQUOTE>

<LI><P>Change 6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation#4">basic.stc.dynamic.allocation</A>] paragraph 4 as follows:</P></LI>

<BLOCKQUOTE>

...[<I>Note:</I> In particular, a global allocation function is not
called to allocate storage for objects with static storage duration
(6.8.6.2 [<A href="https://wg21.link/basic.stc.static">basic.stc.static</A>]), for objects or references with thread
storage duration (6.8.6.3 [<A href="https://wg21.link/basic.stc.thread">basic.stc.thread</A>]), for objects of type
<TT>std::type_info</TT> (7.6.1.8 [<A href="https://wg21.link/expr.typeid">expr.typeid</A>]), or for <DEL>the
copy of an object thrown by a throw expression</DEL> <INS>an exception
object</INS> (14.2 [<A href="https://wg21.link/except.throw">except.throw</A>]). &#8212;<I>end note</I>]

</BLOCKQUOTE>

<LI><P>Change 7.6.1.7 [<A href="https://wg21.link/expr.dynamic.cast#9">expr.dynamic.cast</A>] paragraph 9 as follows:</P></LI>

<BLOCKQUOTE>

The value of a failed cast to pointer type is the null pointer value
of the required result type. A failed cast to reference type throws
<INS>an exception (14.2 [<A href="https://wg21.link/except.throw">except.throw</A>]) of a type that would
match a handler (14.4 [<A href="https://wg21.link/except.handle">except.handle</A>]) of type</INS>
<TT>std::bad_cast</TT> (17.7.4 [<A href="https://wg21.link/bad.cast">bad.cast</A>]).

</BLOCKQUOTE>

<LI><P>Change 7.6.1.8 [<A href="https://wg21.link/expr.typeid#2">expr.typeid</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

...If the glvalue expression is obtained by applying the unary
<TT>*</TT> operator to a pointer<SUP>68</SUP> and the pointer is a
null pointer value (7.3.12 [<A href="https://wg21.link/conv.ptr">conv.ptr</A>]), the <TT>typeid</TT>
expression throws <DEL>the</DEL> <INS>an exception (14.2 [<A href="https://wg21.link/except.throw">except.throw</A>]) of a type that would match a handler of type</INS>
<TT>std::bad_typeid</TT> exception (17.7.5 [<A href="https://wg21.link/bad.typeid">bad.typeid</A>]).

</BLOCKQUOTE>

<LI><P>Change 7.6.2.8 [<A href="https://wg21.link/expr.new#7">expr.new</A>] paragraph 7 as follows:</P></LI>

<BLOCKQUOTE>

When the value of the <I>expression</I> in a
<I>noptr-new-declarator</I> is zero, the allocation function is called
to allocate an array with no elements.  If the value of that
<I>expression</I> is less than zero or such that the size of the allocated
object would exceed the implementation-defined limit, or if the
<I>new-initializer</I> is a <I>braced-init-list</I> for which the number of
<I>initializer-clause</I>s exceeds the number of elements to
initialize, no storage is obtained and the <I>new-expression</I>
<DEL>terminates by throwing</DEL> <INS>throws</INS> an exception
<INS>(14.2 [<A href="https://wg21.link/except.throw">except.throw</A>])</INS> of a type that would match a
handler (14.4 [<A href="https://wg21.link/except.handle">except.handle</A>]) of type
<TT>std::bad_array_new_length</TT> (17.6.4.2 [<A href="https://wg21.link/new.badlength">new.badlength</A>]).

</BLOCKQUOTE>

<LI><P>Change Clause 14 [<A href="https://wg21.link/except#1">except</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

...A handler will be invoked only by <DEL>a <I>throw-expression</I>
invoked</DEL> <INS>throwing an exception</INS> in code executed in the
handler's try block or in functions called from the handler's try
block<DEL> </DEL>...

</BLOCKQUOTE>

<LI><P>Change Clause 14 [<A href="https://wg21.link/except#2">except</A>] paragraph 2 as follows:</P></LI>

<BLOCKQUOTE>

A <I>try-block</I> is a <I>statement</I> (Clause 8 [<A href="https://wg21.link/stmt">stmt</A>]).  A <I>throw-expression</I> is of type <TT>void</TT>.
<DEL>Code that executes a <I>throw-expression</I> is said to
&#8220;throw an exception;&#8221; code that subsequently gets control
is called a &#8220;handler.&#8221;</DEL> [<I>Note:</I>...

</BLOCKQUOTE>

<LI><P>Change 14.2 [<A href="https://wg21.link/except.throw#1">except.throw</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

Throwing an exception transfers control to a handler. <INS>[<I>Note:</I>
An exception can be thrown from one of the following contexts:
<I>throw-expression</I> (see below), allocation functions
(6.8.6.5.2 [<A href="https://wg21.link/basic.stc.dynamic.allocation">basic.stc.dynamic.allocation</A>]), <TT>dynamic_cast</TT>
(7.6.1.7 [<A href="https://wg21.link/expr.dynamic.cast">expr.dynamic.cast</A>]), <TT>typeid</TT> (7.6.1.8 [<A href="https://wg21.link/expr.typeid">expr.typeid</A>]),
<I>new-expression</I> (7.6.2.8 [<A href="https://wg21.link/expr.new">expr.new</A>]), and standard
library functions (16.3.2.4 [<A href="https://wg21.link/structure.specifications">structure.specifications</A>]). &#8212;<I>end
note</I>]</INS> An object is passed and the type of that object
determines which handlers can catch it. [<I>Example:</I>...

</BLOCKQUOTE>

<LI><P>Change 14.2 [<A href="https://wg21.link/except.throw#3">except.throw</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

<DEL>A <I>throw-expression</I></DEL> <INS>Throwing an exception</INS>
copy-initializes (9.5 [<A href="https://wg21.link/dcl.init">dcl.init</A>]<INS>, 11.4.5.3 [<A href="https://wg21.link/class.copy.ctor">class.copy.ctor</A>]</INS>) a temporary object, called the <I>exception
object</I><DEL>, the type of which is determined by removing any top-level
<I>cv-qualifier</I>s from the static type of the operand of
<TT>throw</TT> and adjusting the type from &#8220;array of
<TT>T</TT>&#8221; or &#8220;function returning <TT>T</TT>&#8221; to
&#8220;pointer to <TT>T</TT>&#8221; or &#8220;pointer to function
returning <TT>T</TT>&#8221;, respectively</DEL>.  The temporary is an
lvalue and is used to initialize the variable named in the matching
<I>handler</I> (14.4 [<A href="https://wg21.link/except.handle">except.handle</A>]).  If the type of the
exception object would be an incomplete type or a pointer to an
incomplete type other than (possibly cv-qualified) <TT>void</TT> the
program is ill-formed. <DEL>Except for these restrictions and the
restrictions on type matching mentioned in 14.4 [<A href="https://wg21.link/except.handle">except.handle</A>],
the operand of <TT>throw</TT> is treated exactly as a function
argument in a call (7.6.1.3 [<A href="https://wg21.link/expr.call">expr.call</A>]) or the operand of a
return statement.</DEL> <INS>Evaluating a <I>throw-expression</I> with
an operand throws an exception; the type of the exception object is
determined by removing any top-level <I>cv-qualifier</I>s from the
static type of the operand and adjusting the type from &#8220;array of
<TT>T</TT>&#8221; or &#8220;function returning <TT>T</TT>&#8221; to
&#8220;pointer to <TT>T</TT>&#8221; or &#8220;pointer to function
returning <TT>T</TT>,&#8221; respectively.</INS>

</BLOCKQUOTE>

<LI><P>Change 14.2 [<A href="https://wg21.link/except.throw#4">except.throw</A>] paragraph 4 as follows:</P></LI>

<BLOCKQUOTE>

...[<I>Note:</I> <DEL>an</DEL> <INS>a thrown</INS> exception
<DEL>thrown by a <I>throw-expression</I></DEL> does not propagate to
other threads unless caught, stored, and rethrown using appropriate
library functions; see 17.9.7 [<A href="https://wg21.link/propagation">propagation</A>] and 32.10 [<A href="https://wg21.link/futures">futures</A>]. &#8212;<I>end note</I>]

</BLOCKQUOTE>

<LI><P>Change 14.2 [<A href="https://wg21.link/except.throw#8">except.throw</A>] paragraph 8 as follows:</P></LI>

<BLOCKQUOTE>

A <I>throw-expression</I> with no operand rethrows the currently
handled exception (14.4 [<A href="https://wg21.link/except.handle">except.handle</A>]).  The exception is
reactivated with the existing <DEL>temporary</DEL> <INS>exception
object</INS>; no new <DEL>temporary</DEL> exception object is created.
The exception is no longer considered to be caught; therefore, the
value of <TT>std::uncaught_exception()</TT> will again be
<TT>true</TT>. [<I>Example:</I>...

</BLOCKQUOTE>

<LI><P>Change 14.3 [<A href="https://wg21.link/except.ctor#1">except.ctor</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

As control passes from <DEL>a <I>throw-expression</I></DEL> <INS>the
point where an exception is thrown</INS> to a handler, destructors are
invoked for all automatic objects constructed since the try block was
entered...

</BLOCKQUOTE>

<LI><P>Change 14.3 [<A href="https://wg21.link/except.ctor#3">except.ctor</A>] paragraph 3 as follows:</P></LI>

<BLOCKQUOTE>

The process of calling destructors for automatic objects constructed
on the path from a try block to <DEL>a <I>throw-expression</I></DEL>
<INS>the point where an exception is thrown</INS> is called
&#8220;<I>stack unwinding</I>.&#8221; If a destructor...

</BLOCKQUOTE>

<LI><P>Change 14.4 [<A href="https://wg21.link/except.handle#17">except.handle</A>] paragraph 17 as follows:</P></LI>

<BLOCKQUOTE>

When the handler declares <DEL>a non-constant</DEL> <INS>an</INS>
object, any changes to that object will not affect the <DEL>temporary
object that was initialized by execution of the
<I>throw-expression</I></DEL> <INS>exception object</INS>.  When the
handler declares a reference to <DEL>a non-constant</DEL>
<INS>an</INS> object, any changes to the referenced object are changes
to the <DEL>temporary object initialized when the
<I>throw-expression</I> was executed</DEL> <INS>exception object</INS>
and will have effect should that object be rethrown.

</BLOCKQUOTE>

<LI><P>Change 17.9.5.4 [<A href="https://wg21.link/terminate#1">terminate</A>] paragraph 1 as follows:</P></LI>

<BLOCKQUOTE>

<I>Remarks</I>: Called by the implementation when exception handling
must be abandoned for any of several reasons (14.6.2 [<A href="https://wg21.link/except.terminate">except.terminate</A>]), in effect immediately after <DEL>evaluating the
<I>throw-expression</I> (17.9.5.1 [<A href="https://wg21.link/terminate.handler">terminate.handler</A>])</DEL>
<INS>throwing the exception</INS>.  May also be called directly by the
program.

</BLOCKQUOTE>

</OL>

<BR><BR>
</BODY>
</HTML>
