[dmd-internals] Throwing Errors

Sean Kelly sean at invisibleduck.org
Mon Mar 12 12:34:28 PDT 2012


On Mar 9, 2012, at 9:38 PM, Walter Bright wrote:
> 
> On 3/9/2012 6:29 PM, Jonathan M Davis wrote:
>> The issue of catching Errors came up in D.learn today, and I need some
>> clarification. It has been my understanding that anything which is thrown which
>> is not derived from Exception skips all destructors, scope statements, and
>> finally blocks, meaning that it's generally unsafe to catch them, because your
>> program is potentially in an invalid state. However, it was brought to my
>> attention that the compiler does not currently follow this behavior - all 3 of
>> those get run for Errors at present. So, the question is whether I'm just
>> completely misunderstanding something or whether something has changed.
>> 
>> Is it guaranteed that all thrown Throwables will result in all destructors,
>> scope statements (exit and failure at least), and finally blocks that they pass
>> being executed? Or is it only guaranteed for Exception and its derived types
>> and just so happens to work for other exception types right now?
> 
> It just so happens to work. It's wrong.

I'm on the fence about whether attempting cleanup when an Error is thrown is desired behavior.  If there is no cleanup, why allow Errors to be caught at all?  We may as well simply call abort() at the point they're thrown.


More information about the dmd-internals mailing list