[dmd-internals] Throwing Errors

Jonathan M Davis jmdavisProg at gmx.com
Fri Mar 9 18:29:57 PST 2012


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?

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.

- Jonathan M Davs


More information about the dmd-internals mailing list