I am using Python/Bottle/SqlAlchemy/MySQL for a web service.
I am trying to catch an IntegrityError
raised by calling a stored procedure but I am unable to do that.
Using this
cursor = connection.cursor()
cursor.callproc('my_stored_proc', [arguments])
yields the same result as
try:
cursor = connection.cursor()
cursor.callproc('my_stored_proc', [arguments])
except IntegrityError as e:
print("Error: {}".format(e))
return {"message": e.message}
I get an IntegrityError
exception in both cases. Why is the exception not caught in the latter case?
In my case and may be this helps you too, I was using MYSQL as database so to catch exceptions I need to import exceptions
from django.db.utils import IntegrityError
Then you can try and catch it like this
try:
#your code
except IntegrityError:
#your code when integrity error comes
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With