[Python-ideas] except expression

MRAB python at mrabarnett.plus.com
Tue Feb 18 17:09:14 CET 2014


On 2014-02-18 15:51, Chris Angelico 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()?
>
The current code would use try...except. Would that catch a KeyError
from inside f(y)? Yes.

The problem is that sometimes you want to catch only ZeroDivisionError,
so we need to be able to specify the exception.

The question is whether it should be OK to allow a bare except, where
that would catch a limited number of exceptions, in those cases where
there won't be any risk.


More information about the Python-ideas mailing list