Cannot catch _mysql_exceptions.OperationalError
Jeffrey Froman
jeffrey at fro.man
Fri Jan 18 09:27:02 EST 2008
Bob wrote:
> Here's the code that did not work:
>
> import _mysql_exceptions
> from _mysql_exceptions import OperationalError
>
> try:
> database_code()
> except (_mysql_exceptions.OperationalError, OperationalError), e:
> error_handling()
Both of the above forms work fine here, as does using
MySQLdb.OperationalError:
------------------------------------------------
>>> import MySQLdb
>>> try:
... db = MySQLdb.connect(user='jeffrey', host='localhost')
... except MySQLdb.OperationalError:
... print 'caught'
...
caught
>>> import _mysql_exceptions
>>> try:
... db = MySQLdb.connect(user='jeffrey', host='localhost')
... except _mysql_exceptions.OperationalError:
... print 'caught'
...
caught
>>> from _mysql_exceptions import OperationalError
>>> try:
... db = MySQLdb.connect(user='jeffrey', host='localhost')
... except OperationalError:
... print 'caught'
...
caught
>>> MySQLdb.OperationalError is _mysql_exceptions.OperationalError
True
>>> MySQLdb.__version__
'1.2.2'
------------------------------------------------
Jeffrey
More information about the Python-list
mailing list