Sorting out which exceptions to handle
aleax at aleax.it
Tue Nov 4 16:35:47 CET 2003
Derek Fountain wrote:
> I recently asked a question about the exceptions raised by the MySQLdb
> module. The answer produced a new question. :o) The documentation I was
> pointed at tells me the module has the following exception tree:
> The O'Reilly Python in a Nutshell book says "Generally your code uses a
> statement of the form:
> except module.Error, err:
Well, yes, generally. Not _invariably_, else I would have written that;-).
> with the word "module" in italics. I tried the line:
> except MySQLdb.Error, err:
> and various variations, but always got errors.
What errors? this seems exactly correct (save that you won't catch
*warnings*) according to the above hierarchy. If you also need to
catch warnings together with errors,
except MySQLdb.StandardError, err:
should be satisfactory.
More information about the Python-list