catching SQLAlchemy exceptions

What is the upper level exception that I can catch SQLAlechmy exceptions with ?

>>> from sqlalchemy import exc
>>> dir(exc)
['ArgumentError', 'CircularDependencyError', 'CompileError', 'ConcurrentModificationError', 'DBAPIError', 'DataError', 'DatabaseError', 'DisconnectionError', 'FlushError', 'IdentifierError', 'IntegrityError', 'InterfaceError', 'InternalError', 'InvalidRequestError', 'NoReferenceError', 'NoReferencedColumnError', 'NoReferencedTableError', 'NoSuchColumnError', 'NoSuchTableError', 'NotSupportedError', 'OperationalError', 'ProgrammingError', 'SADeprecationWarning', 'SAPendingDeprecationWarning', 'SAWarning', 'SQLAlchemyError', 'SQLError', 'TimeoutError', 'UnboundExecutionError', 'UnmappedColumnError', '__builtins__', '__doc__', '__file__', '__name__', '__package__']
>>> 

Solution 1:

To catch any exception SQLAlchemy throws:

from sqlalchemy import exc
db.add(user)
try:
  db.commit()
except exc.SQLAlchemyError:
  pass # do something intelligent here

See help(sqlalchemy.exc) and help(sqlalchemy.orm.exc) for a list of possible exceptions that sqlalchemy can raise.

Solution 2:

From the source:

The base exception class is SQLAlchemyError.