Would you want a language to support something like "Retry/Fix"?

Posted by Aaron Anodide on Programmers See other posts from Programmers or by Aaron Anodide
Published on 2012-05-30T22:16:42Z Indexed on 2012/05/30 22:50 UTC
Read the original article Hit count: 255

Filed under:

I was just wondering if a language could support something like a Retry/Fix block?

The answer to this question is probably the reason it's a bad idea or equivalent to something else, but the idea keeps popping into my head.

void F()
{
  try
  {
    G();
  }
  fix(WrongNumber wn, out int x)
  { 
    x = 1;
  }
}

void G()
{
  int x = 0;
  retry<int>
  {
    if(x != 1) throw new WrongNumber(x);
  }
}

After the fix block ran, the retry block would run again...

© Programmers or respective owner

Related posts about programming-languages