scope(failure): get exception

Justin Whear justin at economicmodeling.com
Fri Oct 26 14:37:00 PDT 2012


On Fri, 26 Oct 2012 17:33:48 -0400, Jonathan M Davis wrote:

> On Friday, October 26, 2012 19:53:04 Justin Whear wrote:
>> Is there a way to get the current exception inside a scope(failure)? I
>> have a try..catch around my main loop which simply logs the caught
>> exception and rethrows it. I'd like to replace this with a simple scope
>> (failure) but I haven't found any way to access the exception causing
>> the unwinding.
> 
> If you want to see the exception, you must catch it. scope statements do
> not provide access to exceptions. So, scope works great as long as you
> don't need access to the exception, but if you do, you need to use
> try-catch blocks.
> 
> - Jonathan M Davis

My understanding is that scope(failure) simply lowers to the catch block 
of a try..catch, so there's no implementation obstacle to making the 
exception available.  Are there known syntax or correctness obstacles to 
allowing something like this:

scope(failure)(Exception ex) writeln(ex.msg);


More information about the Digitalmars-d-learn mailing list