[XML-SIG] [Q] SAX Exception

Lars Marius Garshol larsga@ifi.uio.no
22 Nov 1998 18:09:08 +0100

* Tamito Kajiyama
| I'm writing a parser using the SAX module, and want to raise
| exceptions in the methods of saxlib.DocumentHandler
| (e.g. startElement) so that the exceptions are handled by
| saxlib.ErrorHandler's error and fatalError methods.  How can I
| achieve it?

You can't achieve it that way. The SAX exception classes are for the
cases where the parser throws an exception instead of reporting the
error via a method. When the parser throws an exception it loses its
internal state and in these cases the parse is aborted.  (This also
applies when you throw an exception from inside a callback method.)

In other words, what you need to do is to call those methods directly,
which requires you to have a reference to the ErrorHandler yourself.
I'd recommend that you simply wrap the SAX driver completely so that
your clients have no direct access to it. That way you can keep track
of the ErrorHandler object.

--Lars M.