D equivalent of Python's try..else
Mike Parker via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Nov 21 23:41:40 PST 2015
On Saturday, 21 November 2015 at 13:57:01 UTC, Shriramana Sharma
wrote:
>
> Hmm – I forgot Python has `else` for `for` and `while` too. But
> it's a tad difficult to wrap one's mind around the meaning of
> the word `else` in this particular context whereas it actually
> means `nobreak`. Perhaps if this were added to D, `default`
> would be a better choice of keyword, since we all know that
> `default` (as in `switch`) is not executed if `break` happens.
>
> So:
>
> try { code_which_can_throw(); }
> catch { handler(); }
> default { only_if_didnt_throw(); }
> finally { mandatory(); }
>
> How does that look?
Ugly. There's absolutely zero need for this in D.
More information about the Digitalmars-d-learn
mailing list