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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:58:25+00:00 2026-05-14T05:58:25+00:00

In C++, the lifetime of an object begins when the constructor finishes successfully. Inside

  • 0

In C++, the lifetime of an object begins when the constructor finishes successfully. Inside the constructor, the object does not exist yet.

Q: What does emitting an exception from a constructor mean?

A: It means that construction has failed, the object never existed, its lifetime never began. [source]

My question is: Does the same hold true for Java? What happens, for example, if I hand this to another object, and then my constructor fails?

Foo()
{
    Bar.remember(this);
    throw new IllegalStateException();
}

Is this well-defined? Does Bar now have a reference to a non-object?

  • 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-14T05:58:26+00:00Added an answer on May 14, 2026 at 5:58 am

    The object exists, but it’s not been initialized properly.

    This can happen whenever this leaks during construction (not just when you throw an exception).

    It’s a very problematic situation, because some commonly assumed guarantees don’t hold true in this situation (for example final fields could seem to change their value during construction).

    Therefore you should definitely avoid leaking this in the constructor.

    This IBM developerWorks article describes the precautions to take when constructing objects and the reasoning behind those precautions. While the article discusses the subject in the light of multi-threading, you can have similar problems in a single-threaded environment when unknown/untrusted code gets a reference to this during construction.

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

Sidebar

Related Questions

I check a session object and if it does exist then call another method
Will fnc like this extend returned object lifetime? If not, are there a ways
I am new to programming and am having difficulty with understanding object lifetime /
What is the lifetime of an AppDomain in WCF? Does it relate to InstanceContextMode,
I'm curious about shared/static object lifetime in an AppDomain where the RemotingCalls are the
How can I make a variable (object) available for the whole lifetime of the
I'm trying to get my head around how object lifetime and reference counting interact
The question is simple: what is lifetime of that functor object that is automatically
I don't understand this: 3.8/1 The lifetime of an object of type T ends
If not, then does WinRT have its own Garbage Collector? I ask this because

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.