try... except with unknown error types

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Aug 19 22:45:36 CEST 2011


John Gordon wrote:

> In <4e4ec405$0$29994$c3e8da3$5496439d at news.astraweb.com> Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> writes:
> 
>> > You can catch all exceptions by catching the base class Exception:
> 
>> Except that is nearly always poor advice, because it catches too much: it
>> hides bugs in code, as well as things which should be caught.
> 
>> You should always catch the absolute minimum you need to catch.
> 
> I agree, but it did seem to be exactly what he was asking for.

Sure, but if we're giving advice to somebody who is clearly a beginner
(doesn't even know how to deal with a simple NameError from failing to
import a module), it is our responsibility to teach *good* habits, not to
teach him to be a crap programmer.

Even if you don't think it's the ethical thing to do, consider that someday
you might be maintaining code written by the OP :)




-- 
Steven




More information about the Python-list mailing list