The GC, destructors, exceptions and memory corruption

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


Am 13.05.2011 10:12, schrieb Vladimir Panteleev:
> On Fri, 13 May 2011 10:57:37 +0300, Alexander <aldem+dmars at nk7.net> wrote:
> 
>> 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.
> 
> Yes, but what if it's handled (there's a try/catch block around the
> allocation or fullCollect call that invoked the GC)?
> 

I don't think the exception from a destructor should be thrown to an
allocation.. and probably not fullCollect either.
For clear() or delete it /may/ make sense to get exceptions thrown in
the destructor, but it'd be inconsistent if the exceptions would just
vanish or terminate the program otherwise.

It may be sane to just define that destructors are nothrow and if they
throw anyway to terminate the program.

What is the current behaviour anyway? ;)


More information about the Digitalmars-d mailing list