November 22, 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.
November 22, 2015
On Sunday, November 22, 2015 07:41:40 Mike Parker via Digitalmars-d-learn wrote:
> 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.

It's trivially changed to

try { code_which_can_throw(); only_if_didnt_throw(); }
catch { handler(); }
finally { mandatory(); }

So, even assuming that scope statements aren't the best fit (e.g. because you actually need access to the exception, or you don't want it to  be rethrown from the catch block), the default block is pretty pointless as far as I can tell.

- Jonathan M Davis


November 22, 2015
As an idiomatic option there can be `finally(exit)`, `finally(success)` and `finally(failure)` that would mirror semantics of scope guards.
November 22, 2015
On Sunday, 22 November 2015 at 10:01:48 UTC, Kagamin wrote:
> As an idiomatic option there can be `finally(exit)`, `finally(success)` and `finally(failure)` that would mirror semantics of scope guards.

how does this differ from just putting a scope(failure) inside the try block?
it only triggers if no exception is thrown, else it goes to the catch.
1 2
Next ›   Last »