PEP 317: Eliminate Implicit Exception Instantiation

Bernhard Herzog bh at intevation.de
Mon Jun 9 22:33:13 CEST 2003


Steven Taschuk <staschuk at telusplanet.net> writes:

> Quoth Bernhard Herzog:
> > Steven Taschuk <staschuk at telusplanet.net> writes:
[...]
> > > Part of my problem here is that I'm not
> > > familiar enough with real-life uses of the traceback argument.  Do
> > > you use it?
> > 
> > Yes, occasionally.
> 
> I'd like to hear more about this -- in what circumstances, and to
> what end?

One is in the XFig import filter in Sketch (paraphrasing a bit):


        try:
            # ...
            while line:
                tokens = tokenize(line, 1)
                # dispatch on tokens[0]
                # ...
                line = self.readline()
        except SketchLoadError, value:
	    raise SketchLoadError('%d:%s' % (self.lineno, str(value))), None,\
                  sys.exc_traceback

So, basically it's there to put some more information into the error
message. Not all places where SketchLoadError is raised have access to
the line number so it can't easily be done in other ways.

I'm not sure why it uses exc_traceback instead of sys.exc_info()[2] but
the xfig filter is quite old and the code in question might predate
Python 1.5 where exc_info() was introduced. Anyway, Sketch doesn't use
threads so it shouldn't be a problem unless somebody now goes and starts
deprecating sys.exc_traceback ;-)

   Bernhard

-- 
Intevation GmbH                                 http://intevation.de/
Sketch                                 http://sketch.sourceforge.net/
MapIt!                                           http://www.mapit.de/




More information about the Python-list mailing list