scope guards (Re: Ideas regarding flow control and loops)
Bruce Adams
tortoise_74 at yeah.who.co.uk
Mon Nov 5 15:48:51 PST 2007
> >
> I see I needed to RTFM. I see you are suggesting an extension to >existing syntax I missed. Still it makes me uneasy. Overuse of this >feature will make for very hard to read code. scope(exit) serves a >very particular purpose to replace RAII where destructors can't be >used because of GC. I don't actually get scope(success) and >scope(failure) yet (have to RTFM some more). success and failure of >what exactly? The page eplicitly says scope doesn't catch >exceptions. Its only for replacing the finaly of a try catch finally.
Right I have found after some digging Andrei Alexandrescu's
original suggestion.
"I believe three constructs would simplify writing robust code:
1. on_scope_exit { ... code .. }
Executes code upon the current scope's exit. Several on_scope_exit
blocks in a scope are executed LIFO.
2. on_scope_success { ... code ... }
Executes code if the current scope is exited normally (no exception
engendered).
3. on_scope_failure { ... code ... }
Executes code if the current scope is exited via an exception.
"
All specifically to do with exception safety.
Its mentioned in passing on at least two pages (links below) but lacking (as far as I can see lacking a clear definition like this on the digital mars web-site.
http://www.digitalmars.com/d/statement.html
http://www.digitalmars.com/d/exception-safe.html
More information about the Digitalmars-d
mailing list