blanket except clause -- best practice?
John J. Lee
jjl at pobox.com
Tue Oct 28 20:14:33 EST 2003
George Young <gry at ll.mit.edu> writes:
> [python 2.3.2, SuSE Linux 8.2, x86]
[...]
> try:
> stuff
> except _pg.error, msg:
> raise DatabaseError, "error '%s' in '%s'" % ( msg, sql )
> except:
> raise OperationalError, "internal error in '%s'" % sql
>
>
> This accomplishes passing useful info, namely "sql", on with
> the exception. Unfortunately it *loses* info in that upstream
> has no way to know *which* exception triggered this or what args
> it might have been given. I'm trying to think of a clean way
> to improve this. I could do:
Just have an attribute of OperationalError that holds the exception
caught by the except:
John
More information about the Python-list
mailing list