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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:47:49+00:00 2026-06-02T04:47:49+00:00

In C++, if a constructor throws an exception, what destructors are run? In particular,

  • 0

In C++, if a constructor throws an exception, what destructors are run?

In particular, does it make any difference if the exception is during the initialization list or the body?

Also, what about inheritance and members? Presumably all completed constructions get destructed. If only some members are constructed, do only those get destructed? If there is multiple inheritance, do all completed constructors get destructed? Does virtual inheritance change anything?

  • 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-02T04:47:54+00:00Added an answer on June 2, 2026 at 4:47 am

    if a constructor throws an exception, what destructors are run?

    Destructors of all the objects completely created in that scope.

    Does it make any difference if the exception is during the initialization list or the body?

    All completed objects will be destructed.
    If constructor was never completely called object was never constructed and hence cannot be destructed.

    what about inheritance and members? Presumably all completed constructions get destructed. If only some members are constructed, do only those get destructed? If there is multiple inheritance, do all completed constructors get destructed? Does virtual inheritance change anything?

    All completed constructions do get destructed. Yes, only the completely created objects get destructed.

    Good Read:

    Constructor Failures by Herb Sutter

    Especially, love the part where he explains:

    In biological terms, conception took place — the constructor began –, but despite best efforts it was followed by a miscarriage — the constructor never ran to term(ination).

    Incidentally, this is why a destructor will never be called if the constructor didn’t succeed — there’s nothing to destroy. "It cannot die, for it never lived." Note that this makes the phrase "an object whose constructor threw an exception" really an oxymoron. Such a thing is even less than an ex-object… it never lived, never was, never breathed its first.

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

Sidebar

Related Questions

Are there any memory leaks when I throw an exception from a constructor like
With WatiN 1.3, the IE object constructor throws an exception on my machine. See
Is it better that a no-argument constructor throws an impossible exception or has an
What is the best way to throw exception from the constructor initializer? For example:
Constructor for PHP's exception has third parameter, documentation says: $previous: The previous exception used
My team is in the middle of cleaning up our use of throws Exception
Why does this fail with the error : Args are: -normi -nosplash Exception in
Im having some problems to handle constructor exception in derived classes. When the derived
If the constructor ends up with an exception, is the object created exactly the
I'm trying to figure out if the boost::multi_array constructor or resize method can throw

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.