Negative

Walter Bright newshound at digitalmars.com
Wed Mar 1 02:05:46 PST 2006


"Andrew Fedoniouk" <news at terrainformatica.com> wrote in message 
news:du2q1c$4tv$1 at digitaldaemon.com...
>
> "Walter Bright" <newshound at digitalmars.com> wrote in message
>> The new bug in the above code is that the catch block fails to rethrow o.
> Let's say it was an intention. Pretty common by the way.

Perhaps, but the stated point of the example was to show equivalent 
try-catch code to the on_scope example. It isn't equivalent.

> Well try first to explain what will happen on
> on_scope_success { delete baz; throw foo; }
> on_scope_exit { delete baz; throw foo; }
>
> What "lexical order" will be used here? What scope guards will be invoked 
> and so on.

Throwing from inside an on_scope statement is as bad an idea as throwing 
inside a destructor or inside a finally block. Doing it in an on_scope_exit 
or on_scope_failure will result in a double-fault exception. Doing it in an 
on_scope_success will be like throwing at the } of a scope.

> Having on_scope_*** spread all other the "... lots of code ..."  will 
> create
> code maintainance nightmare as to trace visually what will happen and when 
> will not be a task for human anymore.

I submit that based on what's been posted in this thread, it's easier to get 
on_scope *correct* than try-finally, because most of the try-finally 
examples posted here do not work as intended by the author. Not only that, 
the try-finally examples fail in ways that are difficult to write test cases 
for, so the errors are likely to go unnoticed.

> And as far as I understand main idea of on_scope_exit is a sort of poor 
> man struct destructor...
> I suspect that you are thinking about how to remove 'auto'/RAII, right?

No. RAII is for managing resources, which is different from managing state 
or transactions. try-catch is still needed, as on_scope doesn't catch 
exceptions. It's try-finally that becomes redundant, though it is useful to 
keep it because so many people are used to it. 





More information about the Digitalmars-d mailing list