What is the upper level exception that I can catch SQLAlechmy exceptions with ?
>>> from sqlalchemy import exc
>>> dir(exc)
[\'ArgumentError\',
Depending on your version of SQLAlchemy (e.g. 1.0.4), you may need to do a little more to get to the base-SQLAlchemyError
class:
from flask.ext.sqlalchemy import exc
exceptions = exc.sa_exc
try:
my_admin = user_models.User('space cadet', active=True)
db.session.add(my_admin)
db.session.commit()
except exceptions.SQLAlchemyError:
sys.exit("Encountered general SQLAlchemyError. Call an adult!")
this is because sqlalchemy.orm.exc
now has the stanza:
"""SQLAlchemy ORM exceptions."""
from .. import exc as sa_exc, util