Reputation: 744
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?
Upvotes: 7
Views: 11306
Reputation: 17468
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
Upvotes: 1
Reputation: 309929
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()
Upvotes: 10