denis.spir at free.fr
Thu Jan 15 11:54:50 CET 2009
Le Wed, 14 Jan 2009 21:19:11 +0100,
Willi Richert <w.richert at gmx.net> a écrit :
> do you observe the same behavior with traceback.format_exc()? I've used that
> always in such situations which worked all the time.
Actually yes, for the traceback object returned by sys.exc_info() is None. (sys.exc_info() -->
(None,None,None)). Like if there was no exception raised, or like if it had been clear()ed.
But when I don't catch the exception launched by a test program, I get the standard python error
message and the prog stops -- which proves that there *is* an active exception. Simply, I cannot
have it returned by sys.exc_info().
I will try more today to understand why/when/how this happens. As I said, in some circomstances
all works well (sys.exc_info() returns a filled (type,value,traceback) tuple) but as of now I
cannot understand why.
> 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 - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> Tutor maillist - Tutor at python.org
la vida e estranya
More information about the Tutor