[Tutor] traceback

spir denis.spir at free.fr
Wed Jan 14 18:09:51 CET 2009


Hello,

I rather often use exceptions as information providers at design or debug time. A typical use
of mine is to have a test version of methods that wrap standard version:

def run():
	do stuff
	that may
	raise exc
def testRun():
 	try:
		run()
	except Error,error:
		sys.error.write(str(error))

So that I can run a bunch of (possibly failing) tests and still get all worthful info.
Now, the drawback is that I then lose python provided traceback, as for any reason str(exc) does
not return tracback, only the "message". To have the traceback I planned to catch the traceback
manually. The aims whare:
* be able to output the tracback prepended to the message, when useful 
* try to find a more readable (for me) format
* filter it: e.g. print only last trace mark of each module
If you have ideas on the best way to do this, thanks.

I tried to use sys.exc_info() that returns a (type,value,traceback) tuple and the format_tb()
function of the traceback module. *Sometimes* I get the traceback as expected and all is fine. But
in most cases sys.exc_info() returns (None,None,None) like if there was absolutely no active
exception. I cannot consistently reproduce the issue to make a clear diagnosis.

Thank you,
Denis

------
la vida e estranya


More information about the Tutor mailing list