Can I have a list of Exception that mysql.connector can generate?

Asked by Derek Shi

I wonder if there is any documentation about the Exceptions that mysql.connect can generate?

Question information

Language:
English Edit question
Status:
Answered
For:
MySQL Connector/Python Edit question
Assignee:
Geert JM Vanderkelen Edit question
Last query:
Last reply:
Revision history for this message
Geert JM Vanderkelen (geertjmvdk) said :
#1

MySQL Connector/Python follows PEP249 when defining and raising exceptions:
 http://www.python.org/dev/peps/pep-0249/
When you would get some other exception like TypeError, that would be a bug.

If you want to get just a list, here is how you get it within python:

import inspect
from pprint import pprint
from mysql.connector import errors
r = []
for n in inspect.getmembers(errors, inspect.isclass):
  if issubclass(n[1],StandardError):
    r.append(n[0])
pprint(sorted(r))

Result is/should be:
['DataError',
 'DatabaseError',
 'Error',
 'IntegrityError',
 'InterfaceError',
 'InternalError',
 'NotSupportedError',
 'OperationalError',
 'ProgrammingError',
 'Warning']

If you want to catch any Error from MySQL Connector/Python, then you would do it like this (Python v2):

try:
  cursor.execute(...)
except mysql.connector.errors.Error, e:
  print e

There is indeed no documentation yet, but we're working on that.

Can you help with this problem?

Provide an answer of your own, or ask Derek Shi for more information if necessary.

To post a message you must log in.