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 6927153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:00:42+00:00 2026-05-27T11:00:42+00:00

Does the standard have anything to say about an exception that is caught by

  • 0

Does the standard have anything to say about an exception that is caught by reference and what happens to attempts to modify it?

Consider the following code:

class my_exception: public std::logic_error
{
public:
    std::vector<std::string> callstack;
};

void MyFunc()
{
    try
    {
        SomethingThatThrows();
    }
    catch (my_exception & e)
    {
        e.callstack.push_back("MyFunc");
        throw;
    }
}

This is a contrived example, I’m not actually attempting something like this. I was just curious what would happen, based on the suggestion in another thread that exceptions should be caught by const reference.

  • 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-27T11:00:43+00:00Added an answer on May 27, 2026 at 11:00 am

    The exception will change.

    §15.3[except.handle]/17:

    When the handler declares a non-constant object, any changes to that object will not affect the temporary
    object that was initialized by execution of the throw-expression.

    When the handler declares a reference to
    a non-constant object, any changes to the referenced object are changes to the temporary object initialized
    when the throw-expression was executed and will have effect should that object be rethrown.

    So if my_exception is caught outside of MyFunc, we’ll see the "MyFunc" entry in the callstack (e.g. http://ideone.com/5ytqN)

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

Sidebar

Related Questions

I have an App that does the pretty standard operation: It plays audio (streamed
Does C++ standard library and/or Boost have anything similar to the filter function found
Does Haskell standard library have a function that given a list and a predicate,
Does the task parallel library have anything that would be considered a replacement or
What does standard specify about indexing sequence with Attr objects inside NamedNodeMap object? I
Does the standard guarantee that order of equal elements will not change (eh, forgot
Does the C++ Standard Library define this function, or do I have to resort
I'm writing a service that shouldn't have to save anything. It gets some values.
I have a problem with the standard JSpinner.DateEditor (as probably does everyone else). When
I have an interface that defines the behaviour of an object that does some

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.