Why doesn't this work?
try:
1/0
except ZeroDivisionError as e:
e.message += ', you fool!'
raise
The modified message is not used, even though it remains on the exception instance. Is there a working pattern for the above? Behaviour should be like my current workaround below:
try:
1/0
except ZeroDivisionError as e:
args = e.args
if not args:
arg0 = ''
else:
arg0 = args[0]
arg0 += ', you fool!'
e.args = (arg0,) + args[1:]
raise
I'm aware of exception chaining in python3, it looks nice but unfortunately doesn't work in python2. So what is the usual recipe for re-raising an exception in python2?
Note: Because of the warnings and caveats mentioned here, I don't want to dig up the traceback and create a new exception but rather re-raise the existing exception instance.