Re: Destructors are useless?
- From: "Michi Henning" <michi@xxxxxxxxxxx>
- Date: Wed, 27 Apr 2005 23:07:08 +1000
"Helge Jensen" <helge.jensen@xxxxxxx> wrote in message
news:uBBMFPySFHA.2304@xxxxxxxxxxxxxxxxxxxxxxx
> The really usefull information: who forgot to call Dispose, is of course
> not available, but I have a nice MixIn class that I can use to record
> the stacktrace when the object is created and that is definatly also
> usefull to know. It gives you a place to start looking.
>
> While you may not be able to do much with the knowledge in your
> finalizer, you can certainly throw an exception (the program *IS*
> broken,... it forgot to call Dispose()) and the runtime may do
> "good-things" with it. In debug mode the Visual IDE pops up a
> messagebox, alerting you to a bug which would otherwise go unnoticed.
Hmmm... The specification says that, if a destructor throws, the exception
is ignored and execution of that destructor is aborted. Given that you cannot
safely assert in a destructor or write to the console, it seems unlikely that
you could safely record a stack trace: after all, the classes you have to use
to record the stack trace may have long since been finalized. And, if you
can record the stack trace, throwing the exception is useless because that
exception won't go anywhere (that's guaranteed by the spec). Ergo,
destructors are useless during process shutdown. And, because I cannot
control when constructors run, they are useless altogether.
Cheers,
Michi.
--
Michi Henning Ph: +61 4 1118-2700
ZeroC, Inc. http://www.zeroc.com
.
- Follow-Ups:
- Re: Destructors are useless?
- From: Helge Jensen
- Re: Destructors are useless?
- References:
- Destructors are useless?
- From: Michi Henning
- Re: Destructors are useless?
- From: Tom Porterfield
- Re: Destructors are useless?
- From: Helge Jensen
- Destructors are useless?
- Prev by Date: DateTime formatting, Web App, Web Service, SQL Server
- Next by Date: Re: Clear content of a picture box
- Previous by thread: Re: Destructors are useless?
- Next by thread: Re: Destructors are useless?
- Index(es):
Relevant Pages
|