
06.02.2013 0:40, Emil Dotchevski:
I'm not an expert on D but Google tells me that it doesn't support automatic deterministic termination.
Could you please describe what do you mean?
So, if you have a file or a handle open, you need scope(exit) to close it. It also means that the programmer must keep track of all non-memory resources and dispose them "manually" like a C programmer.
In C++, RAII makes scope(exit) unnecessary,
While scope(exit) is some kind of ad-hoc replacement for RAII wrappers, scope(failure) and scope(success) are not. Nowadays scope(failure) and scope(success) are emulated in C++ via ScopeGuard idiom. For motivating examples check: ScopeGuard: http://www.drdobbs.com/cpp/generic-change-the-way-you-write-excepti/18440375... scope(failure)/scope(success): http://channel9.msdn.com/Events/Lang-NEXT/Lang-NEXT-2012/Three-Unlikely-Succ... , http://channel9.msdn.com/Shows/Going+Deep/C-and-Beyond-2012-Andrei-Alexandre... (ScopeGuard11 part)
and catch(...) is the same as scope(failure).
Compare: scope(failure) { rollback1(); }; do1(); scope(failure) { rollback2(); }; do2(); scope(failure) { rollback3(); }; do3(); with try { do1(); try { do2(); try { do3(); } catch(...) { rollback3(); throw; } } catch(...) { rollback2(); throw; } } catch(...) { rollback1(); throw; } -- Evgeny Panasyuk