Title
Rethrowing exceptions in nested handlers
Status
cd1
Section
14.2 [except.throw]
Submitter
Bill Wade

Created on 2000-02-28.00:00:00 last changed 188 months ago

Messages

Date: 2001-04-15.00:00:00

[Moved to DR at 4/01 meeting.]

Date: 2000-04-15.00:00:00

Proposed resolution (04/01):

  1. In 14.2 [except.throw] paragraph 4, change

    When the last handler being executed for the exception exits by any means other than throw; ...
    to
    When the last remaining active handler for the exception exits by any means other than throw; ...

  2. In 14.2 [except.throw] paragraph 6, change

    A throw-expression with no operand rethrows the exception being handled.
    to
    A throw-expression with no operand rethrows the currently handled exception (14.4 [except.handle]).

  3. Delete 14.2 [except.throw] paragraph 7.

  4. Add the following before 14.2 [except.throw] paragraph 6:

    An exception is considered caught when a handler for that exception becomes active (14.4 [except.handle]). [Note: an exception can have active handlers and still be considered uncaught if it is rethrown.]

  5. Change 14.4 [except.handle] paragraph 8 from

    An exception is considered handled upon entry to a handler. [Note: the stack will have been unwound at that point.]
    to

    A handler is considered active when initialization is complete for the formal parameter (if any) of the catch clause. [Note: the stack will have been unwound at that point.] Also, an implicit handler is considered active when std::terminate() or std::unexpected() is entered due to a throw. A handler is no longer considered active when the catch clause exits or when std::unexpected() exits after being entered due to a throw.

    The exception with the most recently activated handler that is still active is called the currently handled exception.

  6. In 14.4 [except.handle] paragraph 16, change "exception being handled" to "currently handled exception."

Date: 2000-02-28.00:00:00

Paragraph 7 of 14.2 [except.throw] discusses which exception is thrown by a throw-expression with no operand.

May an expression which has been "finished" (paragraph 7) by an inner catch block be rethrown by an outer catch block?

    catch(...)    // Catch the original exception
    {
      try{ throw; }    // rethrow it at an inner level
                       // (in reality this is probably
                       // inside a function)
      catch (...)
      {
      }   // Here, an exception (the original object)
          // is "finished" according to 15.1p7 wording

      // 15.1p7 says that only an unfinished exception
      // may be rethrown.
      throw;    // Can we throw it again anyway?  It is
                // certainly still alive (15.1p4).
    }

I believe this is ok, since the paragraph says that the exception is finished when the "corresponding" catch clause exits. However since we have two clauses, and only one exception, it would seem that the one exception gets "finished" twice.

History
Date User Action Args
2008-10-05 00:00:00adminsetstatus: wp -> cd1
2003-04-25 00:00:00adminsetstatus: dr -> wp
2002-05-10 00:00:00adminsetmessages: + msg697
2001-05-20 00:00:00adminsetstatus: ready -> dr
2000-11-18 00:00:00adminsetstatus: review -> ready
2000-05-21 00:00:00adminsetmessages: + msg342
2000-02-28 00:00:00admincreate