Trying to handle an exception raised by SQLAlchemy in my Python code I wrote the following:
import sqlalchemy.exc as sqlalchemy_exc
try:
...
db.session.commit()
except sqlalchemy_exc.SQLAlchemyError:
raise
that isn't a good idea as handled exception is too wide. How to get the particular exception type was raised?
UPDATE
@Dan presented in his answer a reference where several solutions can be found. Two of them are following:
import sqlalchemy.exc as sqlalchemy_exc
...
try:
...
except:
import sys
print(sys.exc_info())
and
import sqlalchemy.exc as sqlalchemy_exc
...
try:
...
except:
import logging
logging.exception('')