The GC, destructors, exceptions and memory corruption

Daniel Gibson metalcaedes at gmail.com
Fri May 13 01:11:47 PDT 2011


Am 13.05.2011 09:57, schrieb Alexander:
> On 13.05.2011 06:53, Vladimir Panteleev wrote:
> 
>> Thus, my question is: what's the expected behavior of D programs when a destructor throws?
> 
>   I would say, the only expected (and correct, IMHO) behavior should be termination of the program because of unhandled exception.
> 
> /Alexander

That sucks if there's no way to handle that exception (other than by try
{ ... } catch {} in the destructor itself)..

But probably the destructor should generally be forbidden to throw, so
if it does and it crashes the program it may be fine.

http://www.digitalmars.com/d/archives/digitalmars/D/What_is_nothrow_for_70451.html
and
http://www.digitalmars.com/d/archives/digitalmars/D/What_is_throwable_86055.html

discussed throwing in destructors a little bit.

Cheers,
- Daniel


More information about the Digitalmars-d mailing list