[lxml-dev] (re-raising) exceptions problem in lxml 2.2beta4
jholg at gmx.de
jholg at gmx.de
Tue Mar 3 11:31:11 CET 2009
Hi,
I just ran into a problem with some code that re-raises exceptions,
where accessing sys.exc_info() returns (None, None, None) instead
of the expected most recent exception information.
This seems to happen if "some operation" is performed on the tree after the exception has been caught and before sys.exc_info() gets invoked.
Looks like lxml clears the exception information somewhere on the way.
Here's a minimal example where the invocation of iterchildren() triggers
the behaviour:
$ cat lxml_reraise.py
import sys
from lxml import etree
print "using lxml version", etree.__version__
root = etree.Element('root')
try:
access = bool(sys.argv[1])
except IndexError:
access = False
try:
raise RuntimeError('Too much foo for bar')
except Exception, e:
if access:
print "children:", list(root.iterchildren())
print sys.exc_info()
Run with lxml 2.1.5:
$ python2.4 lxml_reraise.py
using lxml version 2.1.5
(<class exceptions.RuntimeError at 0x132780>, <exceptions.RuntimeError instance at 0x25f0a8>, <traceback object at 0x25f080>)
$ python2.4 lxml_reraise.py 1
using lxml version 2.1.5
children: []
(<class exceptions.RuntimeError at 0x132780>, <exceptions.RuntimeError instance at 0x1d5828>, <traceback object at 0x1d57d8>)
Run with lxml 2.2beta4:
$ ln -s ~/pydev/tmp/lxml-2.2beta4/build/lib.solaris-2.8-sun4u-2.4/lxml
$ python2.4 lxml_reraise.py
using lxml version 2.2.beta4
(<class exceptions.RuntimeError at 0x132780>, <exceptions.RuntimeError instance at 0x252260>, <traceback object at 0x252170>)
$ python2.4 lxml_reraise.py 1
using lxml version 2.2.beta4
children: []
(None, None, None)
Now, I seem to remember some discussion of changes wrt to exceptions for
lxml 2.2. Might this be an (unwanted) side effect to these changes?
Holger
--
Psssst! Schon vom neuen GMX MultiMessenger gehört? Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger01
More information about the lxml-dev
mailing list