[Python-ideas] except expression

Paul Moore p.f.moore at gmail.com
Tue Feb 18 17:25:44 CET 2014


On 18 February 2014 15:51, Chris Angelico <rosuav at gmail.com> wrote:
> On Wed, Feb 19, 2014 at 2:41 AM, Alexander Belopolsky
> <alexander.belopolsky at gmail.com> wrote:
>> I would not mind
>>
>>  x = 1/f(y) except 0
>>
>> not catching a TypeError that may come from f(y) in most cases.
>
> But should it catch a KeyError from inside f(y), based on the
> translation of d.get()?

Explicit is better than implicit - I think this discussion has done
its job and established that trying to assume a subset of exceptions
to catch isn't going to work. We either allow a bare except to mean
"catch all exceptions" (which exactly the same risks and provisos as a
bare except *statement*) or we make the exception to catch mandatory.

OTOH, there's still an argument for only allowing a single exception
name in the syntax (an "identifier" rather than an "expression" in
syntax terms). If you must catch multiple exceptions, give the
relevant tuple a name.

Paul


More information about the Python-ideas mailing list