例如:
try:
...........
# this exception could be thrown from another method, or just a plain Exception
raise xxxException({'code': 400, 'error': 'Very common message'})
except xxxException, e:
ret = {'code':'The code in e', 'error': 'some specific information'}
raise xxxException(ret)
...........................
我如何从原始异常中提取一些信息,并同时添加我自己的信息?
谢谢。
最佳答案
默认情况下,异常参数存储在 message
字段中。
您可以使用
data = e.message
如果你愿意,你可以改变它
e.message['bananas'] = 'custard'
关于python - 如何获取异常字典信息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25809047/