我有一些用 python Flask 编写的代码,其中我有一个函数如下:
@app.errorhandler(500)
def internal_error(exception):
print "500 error caught"
Run Code Online (Sandbox Code Playgroud)
但是这条消息不足以为我提供足够的信息。我只想打印传递给 errorhandler 的异常的回溯。有没有办法做这个简单的事情?
假设在异常和回溯仍然可用时从上下文中调用错误处理程序sys,您应该能够使用traceback.format_exc.
import traceback
@app.errorhandler(500)
def internal_error(exception):
print "500 error caught"
print traceback.format_exc()
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5780 次 |
| 最近记录: |