[Python-Dev] PEP 463: Exception-catching expressions

Antoine Pitrou solipsis at pitrou.net
Fri Feb 21 17:18:30 CET 2014

On Sat, 22 Feb 2014 02:12:04 +1100
Chris Angelico <rosuav at gmail.com> wrote:
> Overbroad exception handling comes in two ways. One is simply catching
> Exception or BaseException when a narrower class would be better, and
> that's not addressed by this PEP (except insofar as it does not have a
> bare "except:" syntax, and so it forces you to at least be explicit
> about catching BaseException). The other is this:
> try:
>     f(x[i])
> except IndexError:
>     f(default)
> Translating that into this form:
> f(x[i] except IndexError: default)
> means that an IndexError thrown inside f() will not be caught.

Thank you and Nick for the explanation. This is a good point.
I'm still put off by the syntax, though, just like Brett.



More information about the Python-Dev mailing list