[dmd-internals] Throwing Errors

Alex xtzgzorex at gmail.com
Mon Mar 12 13:06:49 PDT 2012


It would be hard to write a framework around D unit tests, for
instance, where you need to catch AssertErrors if things weren't
cleaned up properly (or if it just called abort()). That's just the
first thing that comes to mind.

Regards,
Alex

On Mon, Mar 12, 2012 at 8:34 PM, Sean Kelly <sean at invisibleduck.org> wrote:
> 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.
> _______________________________________________
> dmd-internals mailing list
> dmd-internals at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/dmd-internals


More information about the dmd-internals mailing list