[Python-ideas] except expression

Steven D'Aprano steve at pearwood.info
Wed Feb 19 00:50:45 CET 2014


On Tue, Feb 18, 2014 at 04:09:14PM +0000, MRAB wrote:

> 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.

Having a bare except catch everything in a try...except block, and only 
a few things in an except expression, is a violation of the Principle of 
Least Surprise. Not to mention the Zen about implicit vs explicit.

And the idea that the language designers -- that's us -- might be able 
to predict ahead of time which exceptions aren't risky is laughable. We 
really can't. ANY exception could be a bug in the code, and therefore 
wrong to mask by default. The only person capable of correctly deciding 
which exceptions to catch is the person writing the code.

(And not even always them, but we don't have to solve the problem of 
poor coders writing poor code. It's enough to avoid encouraging it.)


-- 
Steven


More information about the Python-ideas mailing list