www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Throwing an exception in the finally block

What is supposed to happen when an exception is thrown within the "finally"
block?  Being a C++ person, I half expected the program to terminate, but a look
at the exception handling code for D shows that finally blocks have their own
hidden exception handler.  It looks like the intent is to ignore any exceptions
thrown in the "finally" block and to rethrow the original exception.  Is this
correct?

For comparison, I wrote some .NET test code and it looks like as far as .NET is
concerned, the exception generated by the "finally" block is thrown and the
original exception is dropped.  I'm not sure I'm completely happy with either
practice, but calling terminate() seems like it may be overkill.  One dirty
solution would be to chain exceptions together using the next reference in the
Error class, but the chained errors wouldn't be truly handled without all sorts
of TypeInfo stuff in catch blocks.  How do other languages handle multiple
in-flight exceptions?  Are there any that do?


Sean
Nov 16 2004