[lxml-dev] XPath exceptions
Stefan Behnel
stefan_ml at behnel.de
Sun May 13 20:27:07 CEST 2007
Hi again,
Stefan Behnel wrote:
> It is easy to raise different errors from the xpath() method depending on what
> libxml2 tells us about the error source. However, libxml2 also uses a generic
> error code for both syntax and eval errors if the error is not more specific
> (e.g. for a completely unparsable expression), so there are cases where lxml
> cannot tell what kind of error it was, so it would have to default to an eval
> error for the xpath() method. This would still give you different exceptions
> from the XPath() class and the xpath() method for the same unparsable expression.
I now believe that always raising an eval error here is more consistent and
easier to handle. The semantics of raising different errors are flawed anyway,
so having a single evaluation error for an evaluation function is as
consistent as we can get.
Note that this still breaks backwards compatibility as the XPath evaluators
and the xpath() method no longer raise a syntax error but an eval error. You
can work around this to support older lxml versions by excepting on XPathError.
Stefan
More information about the lxml-dev
mailing list