[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
More on SAX Exceptions
- From: Rob Lugt <firstname.lastname@example.org>
- To: email@example.com
- Date: Thu, 12 Jul 2001 23:36:28 +0100
Further to the recent thread about throwing exceptions from user code, I
would like to clarify exactly what a SAX Driver should do when it encounters
There are two places that an application may be told about an exception: on
return from the parse() function or via one of the ErrorHandler interfaces.
I'm looking for clarification about how the following situations should be
1) The SAX Driver encounters some kind of system exception, let's say it
gets an I/O error attempting to read the document entity. Should this (a)
be thrown as a SAXException returned from parse() or (b) should it be
wrapped in a SAXParseException and handed over to
2) A handler method, let's assume EntityResolver::resolveEntity()
encounters an unrecoverable problem. It traps an IOException. It decides
to wrap this in a SAXException and throw it. What should happen next?
Should this exception be (a) returned to the caller of parse() or (b) should
it be wrapped in a SAXParseException and reported to an ErrorHandler if one
3) If you answered (b) to either of the above, then what do you think
should be done when ErrorHandler::warning() throws an Exception. (a) return
it to parse() or (b) wrap the exception in a SAXParseException and call
4) Finally, what about when ErrorHandler::fatalError() rethrows the
SAXParseException, as is the case with DefaultHandler? This must obviously
be returned to parse() otherwise we'd be in a real pickle.
I believe the correct answer to all of the above is (a), throwing a
SAXException will cause the SAX Driver to terminate and return the thrown
exception to the caller of parse(). Without this behaviour how could the
application force a parse to cease prematurely? It couldn't because the
ErrorHandler may deal with it and allow the parse to continue.
So, this brings me to my final question: should a SAX Driver ever call the
ErrorHandler with a real (i.e. unexpected) exception, or will these always
be returned to the caller of parse().