2014-09-12 120 views
1

例如:我怎样才能得到一个例外字典信息?

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

我怎么能提取原始异常的一些信息,并同时添加自己的信息?

谢谢。

+0

更好地利用修改它:' – navyad 2014-09-12 13:18:21

回答

2

默认情况下,异常参数存储在message字段中。 您可以

data = e.message 

把它弄出来,如果你愿意,你可以与除`xxxException为e

e.message['bananas'] = 'custard'