Try blocks are trying

Imperatorn johan_forsberg_86 at hotmail.com
Mon Oct 11 08:55:56 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?

In that case you would just declare x outside and do the call in 
the try


More information about the Digitalmars-d mailing list