[Zope3-dev] Please, no bare 'except:' clauses!
Steve Alexander
steve@cat-box.net
Sun, 10 Nov 2002 22:32:19 +0200
Today, I was looking through the code for various placeful services,
with a view to writing my own placeful service.
I came across various bare 'except:' clauses in the ErrorReporting Service
Zope/App/OFS/Services/ErrorReportingService/ErrorReportingService.py
http://cvs.zope.org/~checkout~/Zope3/lib/python/Zope/App/OFS/Services/ErrorReportingService/ErrorReportingService.py?rev=1.5&content-type=text/plain
The problems with these bare 'except:' clauses are:
* They hide errors by consuming all exceptions.
* They are hard to correct and replace with specific exceptions, because
the original author did not explain the rationale for the except
clause.
Bare 'except:' clauses caused a number of problems with Zope2. There was
a very time-consuming purge on them several months ago. I don't want us
to have to do the same thing for Zope 3.
My recommendations:
* Do not use bare 'except:' clauses. Always qualify them with specific
exception types.
* If you do need to use a bare 'except:' clause, add a comment before it
explaining that you used this bare except clause mindfully, and
explaining the kinds of exception you need to catch, and the reason
the bare 'except:' clause is needed.
Tomorrow I shall check in a change that adds a '# XXX' comment above
each bare 'except:' clause I found. I'd appreciate it if someone who
understands how the code is meant to work can either check in a change
with specific exceptions, or contact me to give me pointers on how to
make the exceptions more specific.
Thanks.
--
Steve Alexander