DMD 0.148 - scope guard

Julio César Carrascal Urquijo jcesar at phreaker.net
Sun Feb 26 09:21:43 PST 2006


James Dunne wrote:
> Kyle Furlong wrote:
> bool LongFunction()
> {
>     bool  passed = false;
> 
>     scope (State save = UIElement.GetState())
>     catch { UIElement.SetState(Failed(save)); writef('0'); }
>     pass { UIElement.SetState(save); writef('1'); }
>     pass { passed = true; writef('2'); }
>     body {
>         ... lots of code ...
>     }
>     exit { writef('3'); }
> 
>     return passed;
> }

This is the best I've seen but:

- Why two "pass" blocks?.
- About "exit" would be better before the "body" block and maybe replace 
it with "finally" to save one more keyword.

I'm also assuming that we could also do one liners without the braces:


bool LongFunction()
{
     bool  passed = false;

     scope State save = UIElement.GetState();
     catch UIElement.SetState(Failed(save));
     pass UIElement.SetState(save);
     finally writef('3');
     body {
         ... lots of code ...
     }

     return passed;
  }



More information about the Digitalmars-d mailing list