[DB-SIG] Unifying exceptions (was: db module wrapper)

Ian Bicking ianb at colorstudy.com
Sat Aug 21 00:01:06 CEST 2004

There might be a clever/tricky solution that would be a little easier to 
implement and more reliable.

Hmm... you could try changing the exceptions, like:

import psycopg
psycopg.DatabaseError = MyDatabaseError

I don't know if this will always stick, or if it's always mutable in 
this way.  Another way might be:

class MyDatabaseError(Exception):
psycopg.DatabaseError.__bases__ = (MyDatabaseError,)

Then you can catch MyDatabaseError, and it will catch 
psycopg.DatabaseError (since it's a subclass).  This might be more 
likely to stick, and work better with the C modules.  (Maybe, I don't 

Ian Bicking  /  ianb at colorstudy.com  /  http://blog.ianbicking.org

More information about the DB-SIG mailing list