【发布时间】:2015-01-23 23:48:01
【问题描述】:
我正在将 Python/Bottle/SqlAlchemy/MySQL 用于 Web 服务。
我试图捕捉通过调用存储过程引发的IntegrityError,但我无法做到。
使用这个
cursor = connection.cursor()
cursor.callproc('my_stored_proc', [arguments])
产生与
相同的结果try:
cursor = connection.cursor()
cursor.callproc('my_stored_proc', [arguments])
except IntegrityError as e:
print("Error: {}".format(e))
return {"message": e.message}
在这两种情况下,我都会收到 IntegrityError 异常。为什么后一种情况没有捕获到异常?
【问题讨论】:
-
您如何/何时提交交易?
IntegrityError可能会在事务提交时引发,而不是在调用存储过程时引发。
标签: python mysql exception stored-procedures sqlalchemy