Why does scope(success) have to use exceptions?

Maxim Fomin maxim at maxim-fomin.ru
Thu Jan 17 08:03:40 PST 2013


On Thursday, 17 January 2013 at 15:35:26 UTC, Andrej Mitrovic 
wrote:
> On 1/17/13, Maxim Fomin <maxim at maxim-fomin.ru> wrote:
>> In any case, your void callScope(ref int x) can be blown up by:
>> int* ptr; callScope(*ptr); so, exceptions may come when they 
>> are
>> not expected.
>
> That was the point of the sample code, exceptions can be thrown 
> at any
> point and as a result the stack will unwind, hence the compiler 
> can
> rewrite callScope to look like callFunc. This isn't about the 
> *lack*
> of exceptions being thrown.

Well, with success scope statement it seems you are right - 
compiler can optimize it in cases like this because if exception 
is thrown when assigning 1 to x, no further statements should be 
performed within callScope.


More information about the Digitalmars-d mailing list