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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:38:41+00:00 2026-06-12T03:38:41+00:00

We consider that an exception in initialization may happen. So we write try /

  • 0

We consider that an exception in initialization may happen. So we write try / catch block.

int f(){
    throw 1;
}

class A
{
public:
    A() try : _k(f())
    {}
    catch (int)
    {
        std::cout << "Exception 1" << std::endl;
    }

private:
    int _k;
};

But the catch rethrows exception on one level deeper. Thats means that next code

try
{
    A a;
} catch(int)
{
    std::cout << "Exception 2" << std::endl;
}

will output:

Exception 1
Exception 2

Why this try / catch block behaves not the same way as ordinary try / catch block?

Full code example: http://ideone.com/XjY2d

  • 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-06-12T03:38:43+00:00Added an answer on June 12, 2026 at 3:38 am

    It seems your question is: Why does a function-level try/catch automatically rethrow the exceptoin? With throwing an exception from a the construction of an object, this object is considered dead before it comes to life. All its subobjects are destroyed. That is, if an exception is thrown during construction there is no object. If the exception would not throw, you’d get a hull of an object into your hands. This is clearly not desirable.

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

Sidebar

Related Questions

It may not be so obvious how respond_to? works in ruby. Consider that: class
Consider the following code: try { int *i = NULL; i[100] = 20; catch
Consider some code that can throw a checked exception (an exception of type Exception
Exceptions are wonderful things, but I sometimes worry that I throw too many. Consider
Consider this simple class that demonstrates RAII in C++ (From the top of my
Consider a following chunk of service: public class ProductService : IProductService { private IProductRepository
Consider a class that's used to represent the results of a GroupBy() . The
Consider a main method: public static void main(String[] args) throws Exception { System.out.println(property=' +
Consider a factory method that I may or may not control, passed to another
Consider a method which might throw an exception with some descriptive text: if ($someCondition)

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.