[Python-ideas] except expression
Steven D'Aprano
steve at pearwood.info
Wed Feb 19 04:25:33 CET 2014
On Wed, Feb 19, 2014 at 01:52:30AM +0000, Rob Cliffe wrote:
>
> On 18/02/2014 23:43, Ethan Furman wrote:
> >On 02/18/2014 03:27 PM, Steven D'Aprano wrote:
> >>
> >>-1 on bare excepts in the expression form.
> >
> >Agreed.
> >
> >--
> >~Ethan~
> I'm prepared to concede this point (as if my opinion as a very junior
> member of the Python community counted for much :-) ). Nick Coghlan and
> Steven D'Aprano made a very strong case in their posts.
> My only real objection is that I would like consistency between "except"
> statements and "except" expressions.
> But I suspect that you (plural), if you had the chance to rewrite
> history, would also want to disallow a bare "except" statement. (Would you?)
> Nick, Steven, Ethan (and anybody else), are you willing to answer this
> question?
> No offence intended, but I'm curious. No, I should be honest: I'm
> hoping to score a debating point.
No offence taken.
I think bare excepts are a bug magnet and violate "Explicit is better
than implicit", and I would like to see them gone, even though they do
have a use at the interactive interpreter for lazy people. Including me.
py> try: this()
... except: None
Yes, I sometimes use that sort of quick-and-dirty construction, but if
the language didn't have it, I wouldn't mind writing Exception after the
except. Well, maybe a tiny bit. But not enough to complain.
I think bare excepts were useful back in ancient days when you
could raise strings, and they were caught by identity not value. But I
think there is strong evidence that this was a mistake: raising strings
was removed in Python 2.6, rather than waiting for Python 3000. I expect
that most people don't even remember that you ever could write things
like
raise "This is an error"
and thank goodness for that :-)
--
Steven
More information about the Python-ideas
mailing list