>>> # Raise the exception with the data you want.
>>> raise Exception('extra information')
Traceback (most recent call last):
File "<pyshell#64>", line 1, in <module>
raise Exception('extra information')
Exception: extra information
>>> # Catch an exception and add extra arguments.
>>> try:
raise Exception()
except Exception as error:
error.args += ('extra information',)
raise
Traceback (most recent call last):
File "<pyshell#68>", line 2, in <module>
raise Exception()
Exception: extra information
>>>
您可以尝试以下两种方法之一:
通过添加更多参数,可以添加任意多个附加数据字段。
wes' answer没有帮到我,因为我实际上想引发一个异常,不仅记录它。
以下是我所做的(
client
是Raven Sentry的客户):我使用
logging
库记录异常,因此在稍微调试代码之后,我注意到extra
参数:传递exc_info=1与调用
logger.exception
相同。但是,exception()
不接受kwargs,这是使用extra
参数所必需的。这些值将显示在Sentry错误仪表板的“附加数据”部分。
相关问题 更多 >
编程相关推荐