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.