Hi, do you observe the same behavior with traceback.format_exc()? I've used that always in such situations which worked all the time.
Regards, wr Am Mittwoch, 14. Januar 2009 18:09:51 schrieb spir: > 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 > _______________________________________________ > Tutor maillist - [email protected] > http://mail.python.org/mailman/listinfo/tutor _______________________________________________ Tutor maillist - [email protected] http://mail.python.org/mailman/listinfo/tutor
