我是Flask的新手,我正尝试在python中显示Built-In Exceptions,但似乎无法在它们的末端显示它们。
注意:
set FLASK_DEBUG = 0
代码:
def do_something:
try:
doing_something()
except Exception as err:
return f"{err}"
期望:
现实:
也:
答案 0 :(得分:1)
尝试一下:
def do_something:
try:
doing_something()
except Exception as err:
return f"{err.__class__.__name__}: {err}"
答案 1 :(得分:1)
IIntfA
为您提供了一个功能,使您可以在整个{
"NotificationDetails": {
"@xmlns": "http://schemas.microsoft.com/netservices/2010/10/servicebus/connect",
"@xmlns:i": "http://www.w3.org/2001/XMLSchema-instance",
"NotificationId": ...
"Location": ...
"State": "Completed",
"EnqueueTime": "2019-03-11T18:09:51Z",
"StartTime": "2019-03-11T18:09:51.1753858Z",
"EndTime": "2019-03-11T18:09:51.4209862Z",
"NotificationBody": .....
"Tags": ...
"TargetPlatforms": "template",
"ApnsOutcomeCounts": {
"Outcome": {
"Name": "Success",
"Count": "1"
}
}
}
}
中注册错误处理程序;您可以执行以下操作:
Flask
在我看来,这是可行的方法。 -以app
中的结构为例奠定了坚实的基础。
拥有统一的异常处理程序,可以标准化您的def handle_exceptions(e):
# Log exception in your logs
# get traceback and sys exception info and log as required
# app.logger.error(getattr(e, 'description', str(e)))
# Print traceback
# return your response using getattr(e, 'code', 500) etc.
# Exception is used to catch all exceptions
app.register_error_handler(Exception, handle_exceptions)
处理,可视化和日志记录,将使您的生活更加美好。 :)