scope(faliure) flow control.

Casper Færgemand" <shorttail at hotmail.com> Casper Færgemand" <shorttail at hotmail.com>
Sat Dec 28 12:50:41 PST 2013


On Saturday, 28 December 2013 at 20:31:14 UTC, TheFlyingFiddle 
wrote:
> int foo()
> {
>    scope(failure) return 22;
>    throw new Exception("E");
> }
>
> unittest
> {
>    assert(foo() == 22);
> }
>
> Is this defined behavior? At least in x64 dmd the exception is 
> swallowed and the assert evaluates to true.
>
> In any case what should happen? Should the method return or 
> should the exception be propagated up the callstack?

It's rewritten as follows:

int foo()
{
    try {
       throw new Exception("E");
    } catch (Exception e) { // or whatever the D syntax is, I 
never used it
       return 22;
    }
}

So yes, it's intended. scope(exit) uses finally instead of catch.


More information about the Digitalmars-d-learn mailing list