Try blocks are trying

Imperatorn johan_forsberg_86 at
Mon Oct 11 12:12:58 UTC 2021

On Sunday, 10 October 2021 at 16:12:31 UTC, Carl Sturtivant wrote:
> Why is it that a try block is defined to establish a scope?
> ```
>     try {
>         auto x = frgl();
>     }
>     // ...
>     // x undefined here
> ```
> What is the benefit of this? If try (like static if/foreach) 
> did NOT establish a scope, then this annoyance would go away. 
> And if a scope was desired for some reason, then an extra pair 
> of braces could be written within.
> Right now rewriting the above requires getting the return type 
> of frgl and declaring x to be of that type before the try block.
> Design error?

My gut instinct tells me problems would arise if try didn't 
introduce a scope. It's not a compile time concept like static if.

If we had a static try I would probably agree

More information about the Digitalmars-d mailing list