我怎么能得到一个例外dict信息?

时间:2014-09-12 13:06:41

标签: python django python-2.7

例如:

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)
...........................

我如何从原始异常中提取一些信息,并同时添加我自己的信息?

感谢。

1 个答案:

答案 0 :(得分:2)

默认情况下,exception参数存储在message字段中。 你可以用

来解决它
data = e.message

如果你愿意,你可以用

改变它
e.message['bananas'] = 'custard'