使用e.args
,e.message
已被弃用。
try:
assert False, "Hello!"
except AssertionError as e:
e.args += ('some other', 'important', 'information', 42)
raise
这将保留原始的回溯。然后其最后一部分如下所示:
AssertionError: ('Hello!', 'some other', 'important', 'information', 42)
在Python 2.7和Python 3中均可使用。