Board index » cppbuilder » Terminate() inside form constructor avoids destructor

Terminate() inside form constructor avoids destructor

It seems that calling Application->Terminate() inside of a form
constructor causes the form's destructor to not get called.  Is
this actually the case?  I was hoping the form would still get
constructed, and then destructed, as the destructor cleans up
some new()s and I don't want to mess with those funky auto_ptrs.
Putting it somewhere else would be inelegant.
 

Re:Terminate() inside form constructor avoids destructor


Quote
"David B. Held" wrote:
> It seems that calling Application->Terminate() inside of a form
> constructor causes the form's destructor to not get called.  Is
> this actually the case?  I was hoping the form would still get
> constructed, and then destructed, as the destructor cleans up
> some new()s and I don't want to mess with those funky auto_ptrs.
> Putting it somewhere else would be inelegant.

If your constructor throws an exception, then your destructor will not
be called, as the constructor did not *successfully* complete.  That is
why those funky auto_ptrs are so useful as class members, because they
finish constructing in your initialiser list before starting on the body
of your constructor, so their destructor is guaranteed to be called.
See Scott Meyers 'Effective C++' for more on this topic...

However, that isn't your problem here (from what you say) as
Application->Terminate does not throw an exception, and should lead to
an orderly program shut down.  So long as the form has an owner (and
that owner has an owner etc.) you should get a destructor.

Anyone else seen this?

AlisdairM

Other Threads