DIP 1002 (TryElseExpression) added to the queue

Walter Bright via Digitalmars-d digitalmars-d at puremagic.com
Wed Sep 28 17:35:47 PDT 2016


On 9/28/2016 3:12 PM, Idan Arye wrote:
> Consider this:
>
>     try {
>         auto foo = Foo();
>     } catch (FooCreationException) {
>         // ...
>     } else {
>         foo.doSomethingWithFoo();
>     }

I agree with Steven. Having the 'else' continue on with a scope that is already 
closed by } is very weird and unsettling.

You could argue that D already does this with static if:

     static if (x)
     {
         int x;
     }
     x = 3;

and that disturbs some people. But it is conditional compilation, and no other 
way around it has been proposed, and it has major benefits. (C++'s static if 
proposal does not allow this, a decision that I predict they'll come to regret.)

Adding more cases of this sort of thing should be approached with great 
trepidation, and is not justified if it is only a minor improvement.


More information about the Digitalmars-d mailing list