Re: ???: telling tracebacks to stop - reraising exceptions proposal

Steven D. Majewski (sdm7g@elvis.med.virginia.edu)
Sat, 26 Mar 1994 00:11:24 -0500

In the past, I have registered some complaints that Python's
exceptions are sometimes too coarse grained - that you often
have to catch and exception and check the value parameter to
see if it's THE exception you are actually expecting to handle.

This would not be a problem if you could just re-raise the
exception. You CAN raise the same exception - not quite the
same thing as the traceback now will point to your raise
of the exception, not the original error which you were not
prepared to handle. ( OK if I'm the only user of the code,
but a dirty trick to play on someone else! :-)

This thread on printing of tracebacks has reminded me of
that problem, but it has also suggested a solution:

I propose that the 'raise' statement be given an optional
third parameter, which would be a traceback object.

A *REAL* reraise of an exception would then be:
raise sys.exc_type, sys.exc_value, sys.exc_traceback
(Keeping the original traceback )

And Tom Burnette's problem would become:
raise sys.exc_type, sys.exc_value,sys.exc_traceback.tb_last.tb_last

'raise exception,value' would still generate a new traceback.

- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics