DMD 0.148 - scope guard
Lionello Lunesu
lio at remove.lunesu.com
Mon Feb 27 02:48:31 PST 2006
"Walter Bright" <newshound at digitalmars.com> wrote in message
news:dtsr1i$1u4v$4 at digitaldaemon.com...
>
> "Hasan Aljudy" <hasan.aljudy at gmail.com> wrote in message
> news:dtsfm5$1h2i$1 at digitaldaemon.com...
>> Why not just reuse "finally"?
>>
>> void func()
>> {
>> init_some_reource();
>> foo(); // foo throws an exception
>> //func doesn't catch the exception
>> //but it has a finally clause
>>
>> finally //aka on scope exit, whether success or fail
>> {
>> release_the_resource();
>> }
>> }
>
> finally does work for on_scope_exit, but it leaves on_scope_success and
> on_scope_failure hanging.
Similar to allowing multiple "finally" statements, even without "try", you
could allow multiple "catch", also without "try":
finally writefln("done");
dofoo();
catch dofoo_undo();
dobar();
where the catch would also rethrow the exception being caught.
Now we just need something sensible for on_scope_success and we're done ; )
L.
More information about the Digitalmars-d
mailing list