Killing Another Bug

Stephen Hansen apt.shansen at gmail.com
Fri Dec 4 15:46:38 EST 2009


On Fri, Dec 4, 2009 at 7:52 AM, Victor Subervi <victorsubervi at gmail.com>wrote:

>     except:
>


>     except:
>       pass
>

If you want any hope of fixing the bug, remove both of these. Really -- do
not use bare excepts.

In the first one, it looks like you're expecting sometimes there to be an
exception: that's okay. If you think an operation will produce one, its okay
to catch it if you know how to handle it.  But do NOT use bare excepts.
Catch the actual exception you are expecting-- a KeyError maybe? ValueError?
I don't know, can't tell without knowing what "fn" does.

In the second-- that bare except with a pass is doing absolutely nothing but
_destroying_ any chance you have of finding out what the bug IS and fixing
the bug. Remove that entire try/except: pass statement. Really. You
absolutely have to do it. The only reason you have not already found and
fixed this bug is that you have done this-- you can't do this and then ask
us to find the bug for you.

Bare excepts are there for a reason, and there are times to use them. But
those are the exception and not the rule; and the time to use a except: pass
construct is NOT when you're trying to fix a bug.


--S
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20091204/0a969b34/attachment-0001.html>


More information about the Python-list mailing list