Throwable class design

simendsjo simendsjo at gmail.com
Wed Jan 30 01:13:07 PST 2013


On Wednesday, 30 January 2013 at 09:05:22 UTC, rumbu wrote:
> On Wednesday, 30 January 2013 at 08:44:52 UTC, Jonathan M Davis 
> wrote:
>>
>> Exceptions get rethrown all the time. Heck, that's what 
>> happens with finally,
>> scope(failure), and scope(exit). It's what you do when you 
>> need to react to
>> the fact that the exception was thrown (maybe even to the 
>> specific exception)
>> but aren't going to handle it in that section of code.
>>
>> Now, mutating the exception before rethrowing is another 
>> thing. I'd tend to
>> think that that was bad practice, but I suppose that it could 
>> be useful upon
>> occasion. In general though, if I wanted to add information, 
>> I'd wrap the
>> caught exception in a new exception and throw that.
>>
>> - Jonathan M Davis
>
> Exceptions are not rethrown, finally block is executed *after* 
> throwing/catching the exception. I don't know the details of 
> the scope(*) implementations, but I doubt that they are 
> rethrowing any exceptions. Exceptions are propagated, not 
> rethrown with a mutated message or field.

Finally needs to rethrow the exception at the end of the scope. 
If an exception is thrown in the finally clause, it is chained at 
the end of the exception currently in flight.

I'm pretty sure scope(*) just lowers to try/catch/finally:
try {
   // something
   // scope(success)
} catch (Exception) {
   // scope(failure)
} finally {
   // scope(exit)
}


More information about the Digitalmars-d mailing list