try... except with unknown error types
nagle at animats.com
Sat Aug 20 16:15:41 EDT 2011
On 8/19/2011 1:24 PM, 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.
Right. When in doubt, catch EnvironmentError. That means something
external to the program, at the OS or network level, has a problem.
"Exception" covers errors which are program bugs, like references to
undefined class members.
More information about the Python-list