Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6986627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:50:00+00:00 2026-05-27T18:50:00+00:00

As a follow-up to my previous question : If I change the code as

  • 0

As a follow-up to my previous question:

If I change the code as follows:

struct ExceptionBase : virtual std::exception{};
struct SomeSpecificError : virtual ExceptionBase{};
struct SomeOtherError : virtual ExceptionBase{};

void MightThrow();
void HandleException();
void ReportError();

int main()
{
  try
  {
    MightThrow();
  }
  catch( ... )
  {
    HandleException();
  }
}

void MightThrow()
{
  throw SomeSpecificError();
}

void HandleException()
{
  try
  {
    throw;
  }
  catch( ExceptionBase const & )
  {
    // common error processing
  }

  try
  {
    throw;
  }
  catch( SomeSpecificError const & )
  {
    // specific error processing
  }
  catch( SomeOtherError const & )
  {
    // other error processing
  }

  try
  {
    ReportError();
  }
  catch( ... )
  {
  }
}

void ReportError()
{
  throw SomeOtherError();
}

The “last handler” for the original exception (i.e. the one in main) has not exited when the second exception is thrown, so are both exceptions active? Is the original exception still available once we leave the handler for the second exception?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T18:50:01+00:00Added an answer on May 27, 2026 at 6:50 pm

    C++11 (N3242):

    15.1p4: The memory for the exception object is allocated in an unspecified way, except as noted in 3.7.4.1. If a
    handler exits by rethrowing, control is passed to another handler for the same exception. The exception
    object is destroyed after either the last remaining active handler for the exception exits by any means other
    than rethrowing, or the last object of type std::exception_ptr (18.8.5) that refers to the exception object is
    destroyed, whichever is later.

    (std::exception_ptr is a C++11 feature, and isn’t used in your example code.)

    15.3p7: A handler is considered active when initialization is complete for the formal parameter (if any) of the catch clause. … A handler
    is no longer considered active when the catch clause exits or when std::unexpected() exits after being
    entered due to a throw.

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

    15.1p8: A throw-expression with no operand rethrows the currently handled exception (15.3).

    Or equivalently, I think, throw; always refers to the exception caught by the innermost catch block which is currently executing. Except that I haven’t defined ‘innermost’ and ‘executing’ as carefully as the Standard defined all its terms above.

    And yes, more than one exception object can be allocated at a time, and C++ is required to make sure they live long enough to do “the right thing” when you try to rethrow.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

To follow from my previous question about virtual and multiple inheritance (in a cross
Follow up to a previous question , I have some code that needs to
to follow my previous question: XDoclet, a dead tool? what tool can I use
This question is a follow up to my previous question about getting the HTML
This is a follow up question to a previous question I asked about calculating
In a follow-up to a previous question regarding exceptions, what are best practices for
As a follow up to my previous question , I am wondering how to
This is a follow-up to a previous question I had about interfaces. I received
In a follow-up to a previous question, let's say I have 3 tables, A,
This is a follow up to my previous question: Problem passing parameters via Iframe

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.