Re: What happens if an exception's thrown in a derived constructor?

From: Tom Widmer (tom_usenet_at_hotmail.com)
Date: 10/07/04


Date: Thu, 07 Oct 2004 16:52:47 +0100

On Thu, 07 Oct 2004 14:37:03 GMT, Ken Overton <ken.overton@gmail.com>
wrote:

>
>Is there still a base-class object hanging around that needs to be
>disposed-of? How do the resources allocated in the base class get
>destroyed?

Everything for which construction has already completed (e.g. members
and base classes if you're in the constructor body of the derived
class) gets its destructor called. Anything currently undergoing
construction (e.g. the derived class, the member being constructed if
applicable) doesn't get its destructor called. Memory for the class is
deallocated using the operator delete call that matches the operator
new called.

It's all pretty logical.

Tom



Relevant Pages

  • Re: object relational database versus "inteligent" serialization
    ... You all say it's because base class must initialize its members but I ... construction for that matter, would complicate matters horribly. ... Let _me_ worry about proper initialization. ... But it has one limitation. ...
    (comp.lang.java.programmer)
  • Re: mulitple inheritance and constructors?
    ... > I just tried something with multiple inheritance and I have a problem ... > with the construction of my object. ... > There's a base class Base, ... IIRC in case of virtual inheritance it is *always* the most derived class, ...
    (comp.lang.cpp)
  • Re: Require base class member to be populated by derived classes.
    ... But it's not very different from any of the other half-way solutions that had already been suggested (nor was it clear from your post that your requirement was that the "population" happen during construction). ... In all cases, the general idea is: have some code in the derived class that initializes the members, and have some code in the base class that verifies that initialization. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: abstract sub programs overriding
    ... > construction properly. ... derived class require services from its base class, ... Bases may need to invoke services from derived classes, ...
    (comp.lang.ada)
  • Re: method prolog/epilog
    ... Do you mean you want the base class to do some ... of its own contstruction only after the child class is finished ... doing its construction? ... code and I found this trick, I'd recommend getting rid of it. ...
    (comp.lang.cpp)