My code works, but I am thinking there is something wrong with my understanding, or possibly (gasp) an error in Python's raise
behavior.
I am looping over a set of arguments. I capture the first error and want to raise it after I have finished looping, with the original traceback etc as described in “Inner exception” (with traceback) in Python?
I obviously want the loop to process all the arguments, and only then tell me what went wrong.
error = None
for arg in arguments:
try:
process(arg)
except ValueError, err:
if not error:
error = sys.exc_info()
if error:
raise error[0], error[1], error[2]
The last line is the problematic line. It works (demo: http://ideone.com/HFZETm -- note how it prints the traceback from the first error, not the last one), but it seems extremely clunky. How could I express that more succinctly?
raise error
would seem more elegant, but it behaves as if I had simply raise error[0]
(or perhaps raise error[1]
). raise *error
is a syntax error.