D equivalent of Python's try..else
Kagamin via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Nov 22 01:40:12 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`.
In a way `for` and `while` are conditional statements like `if`:
when condition is true, positive branch is executed; when
condition is false, `else` clause is executed.
> try { code_which_can_throw(); }
> catch { handler(); }
> default { only_if_didnt_throw(); }
> finally { mandatory(); }
>
> How does that look?
Both `default` and `else` match if previous clauses didn't match,
there's no difference in their semantics, in `try` statement they
would match if other `catch` clauses didn't match no matter if
there's exception or not.
More information about the Digitalmars-d-learn
mailing list