Detecting exception unwinding

Ola Fosheim Grøstad via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Feb 6 06:25:21 PST 2016


On Saturday, 6 February 2016 at 06:08:41 UTC, cy wrote:
> Sorry, years of python programming have made me shy of 
> destructors. It just looks a little less "magic" to me if I 
> specify the destruction explicitly after creating the object, 
> using the "scope(exit)" syntax.

That is error-prone!

In Python you are supposed to use the with-statement to get RAII 
like behaviour. So you use __enter__ and __exit__ methods on the 
context-manager. From the Python docs:

«The context manager’s __exit__() method is invoked. If an 
exception caused the suite to be exited, its type, value, and 
traceback are passed as arguments to __exit__(). Otherwise, three 
None arguments are supplied.»

See, even Python supports this. :-)



More information about the Digitalmars-d-learn mailing list