[Python-ideas] except expression

Chris Angelico rosuav at gmail.com
Wed Feb 19 04:37:25 CET 2014


On Wed, Feb 19, 2014 at 2:25 PM, Steven D'Aprano <steve at pearwood.info> wrote:
> 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 :-)

They were caught by identity? Ouch. Definite bug magnet. In that case,
yeah, you'd normally want to just put a bare "except:" and then decide
what to do with the exception... only... a bare except can't capture
the thing thrown, so how do you decide? IMO having to turn to
sys.exc_info is wrong; you should be able to work within the construct
of the try/except block.

ChrisA


More information about the Python-ideas mailing list