D equivalent of Python's try..else

Russel Winder via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Nov 21 07:55:45 PST 2015


On Sat, 2015-11-21 at 19:26 +0530, Shriramana Sharma via Digitalmars-d-
learn 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(); }
> 

There have been, over the years, many debates about changing the "else"
keyword to something else, and always nothing is changed because "else"
is the least worst name. In the case above, I could live with "else" or
"default" since it doesn't have much conflict – but I bet this could
easily become a "bikeshed issue".

-- 
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:russel.winder at ekiga.net
41 Buckmaster Road    m: +44 7770 465 077   xmpp: russel at winder.org.uk
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: This is a digitally signed message part
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20151121/2f464e93/attachment.sig>


More information about the Digitalmars-d-learn mailing list