[dmd-internals] Throwing Errors

Walter Bright walter at digitalmars.com
Fri Mar 9 21:38:52 PST 2012



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've been completely certain that such was _not_ guaranteed unless the
> exception type is Exception or derived from Exception, but I can't find any
> support for that searching the docs or newsgroup save for what I've said about
> it myself. So, I'd like official clarification on the matter.
>




More information about the dmd-internals mailing list