I have some code written in python flask, where I have a function as follows:
@app.errorhandler(500)
def internal_error(exception):
print "500 error caught"
But this message is not sufficient enough to provide me with enough information. I just want to print the traceback for the exception that is passed to errorhandler. Is there any way to do this simple thing?
Assuming that the error handler is called from within a context when the exception and traceback are still available from sys
, you should be able to use traceback.format_exc
.
import traceback
@app.errorhandler(500)
def internal_error(exception):
print "500 error caught"
print traceback.format_exc()
I think you can solve it like this:
import sys
import traceback
@app.errorhandler(500)
def internal_error(exception):
print("500 error caught")
etype, value, tb = sys.exc_info()
print(traceback.print_exception(etype, value, tb))
You can print the traceback information
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