From 9d7c027cb76d467d2f044952287f92bb61016617 Mon Sep 17 00:00:00 2001 From: Jason Kirtland Date: Mon, 22 Oct 2007 19:24:02 +0000 Subject: - Now guarding against broken DB-APIs when wrapping their exceptions. - Added an explicit test for exception wrapping. --- lib/sqlalchemy/exceptions.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/exceptions.py b/lib/sqlalchemy/exceptions.py index 9c7caedd0..decde0efa 100644 --- a/lib/sqlalchemy/exceptions.py +++ b/lib/sqlalchemy/exceptions.py @@ -96,8 +96,14 @@ class DBAPIError(SQLAlchemyError): instance = classmethod(instance) def __init__(self, statement, params, orig): - SQLAlchemyError.__init__(self, "(%s) %s" % - (orig.__class__.__name__, str(orig))) + try: + text = str(orig) + except (KeyboardInterrupt, SystemExit): + raise + except Exception, e: + text = 'Error in str() of DB-API-generated exception: ' + str(e) + SQLAlchemyError.__init__( + self, "(%s) %s" % (orig.__class__.__name__, text)) self.statement = statement self.params = params self.orig = orig -- cgit v1.2.1