exception handling in complex Python programs

eliben eliben at gmail.com
Fri Aug 22 00:57:49 EDT 2008


> Here is an example from a Django web app: when there is a bug, a
> generic Exception is thrown and Django catches it and reports a
> beautifully formatted stack trace. When something must be reported to
> the user, a MyAppException is thrown (not the real name). The HTTP
> request handler for the application is wrapped in a single try:...
> except MyAppException:.... the big idea is that there should be a
> maximum of two try/except blocks on the stack at any particular point
> in time [1]: at a high level (already mentioned) and for wrapping
> primitive "execute" operations against Rpy and MySQLdb.

This actually makes lots of sense as is exactly what Ned Batchelder
wrote here:
http://nedbatchelder.com/text/exceptions-in-the-rainforest.html

    * A-layer generates exceptions,
    * B-layer can often ignore the whole issue, and
    * C-layer decides what to do

It's worth a read.




More information about the Python-list mailing list