Detecting exception unwinding

cy via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 6 14:51:45 PST 2016


On Saturday, 6 February 2016 at 14:25:21 UTC, Ola Fosheim Grøstad 
wrote:
> See, even Python supports this. :-)

And D supports the "with" statement in python, in the form of 
"scope()" statements. The D way is slightly less misleading too, 
as

with somethingThatFails() as e:
   print(e)

doesn't make it obvious that neither __enter__ nor __exit__ will 
be called if you raise an exception in the creation of the 
object, or that if you raise an exception in __enter__, then 
__exit__ won't be called.

auto e = somethingThatFails()
scope(failure) cleanup(e);

makes more sense to me, since it's blatantly obvious that the 
construction (and entering) process isn't covered by the cleanup 
routine.


More information about the Digitalmars-d-learn mailing list