Karl Waclawek | 21 Dec 2003 07:04

Re: [xml-dev] SAX and endDocument


> I was working with Xerces-J this weekend and encountered what I thought was
> a
> major bug-- however upon rereading the SAX API docs I suspect I may be
> mistaken. For some reason I was under the impression that the endDocument
> function was guaranteed-- meaning, that even in an exceptional circumstance
> endDocument would be called. This allowed a guaranteed place (expeccially in
> the case of filters) to do cleanup after a parse.
> 
> This is definitely the case for AElfred2, but the API docs are not crystal
> clear on the subject (though I thought they used to be).  With AElfred2,
> even in the case of a user generated exception the endDocument handler will
> be called. In Xerces if an exception occurs it stops the process completely
> omitting the endDocument call.

When I wrote the SAX2 wrapper for Expat I had it the Xerces way, but
then I re-read the specs and changed my mind, mostly because the docs
for endDocument() use the same wording as for startDocument()
(which is guaranteed):

"The SAX parser will invoke this method only once..."

On the other hand one could say that because a SAX parser does not throw
exceptions for parse errors, exception handling is outside of its scope
and one should therefore follow the normal practice that an exception 
(thrown by an error handler) really should force parse() to return immediately.
This would make more sense to me.

So, instead of answering your question I will join your request
for clarification.
(Continue reading)

John Wilson | 21 Dec 2003 11:18
Picon

Re: Re: [xml-dev] SAX and endDocument


On 21 Dec 2003, at 06:04, Karl Waclawek wrote:
>
[Snip]
> This is definitely the case for AElfred2, but the API docs are not  
> crystal
>> clear on the subject (though I thought they used to be).  With  
>> AElfred2,
>> even in the case of a user generated exception the endDocument  
>> handler will
>> be called. In Xerces if an exception occurs it stops the process  
>> completely
>> omitting the endDocument call.
>
> When I wrote the SAX2 wrapper for Expat I had it the Xerces way, but
> then I re-read the specs and changed my mind, mostly because the docs
> for endDocument() use the same wording as for startDocument()
> (which is guaranteed):
>
> "The SAX parser will invoke this method only once..."
>
> On the other hand one could say that because a SAX parser does not  
> throw
> exceptions for parse errors, exception handling is outside of its scope
> and one should therefore follow the normal practice that an exception
> (thrown by an error handler) really should force parse() to return  
> immediately.
> This would make more sense to me.
>
> So, instead of answering your question I will join your request
(Continue reading)

Karl Waclawek | 21 Dec 2003 15:46

Re: Re: [xml-dev] SAX and endDocument


> > So, instead of answering your question I will join your request
> > for clarification.
> >
> 
> This thread on Sax-Devel is relavent to this discussion  
> http://www.geocrawler.com/mail/thread.php3?subject=%5BSax- 
> devel%5D+endDocument+throwing+an+exception&list=13179
> 
> My understanding is that a parser is required to always call  
> endDocument()

OK, then I would say this should be more clear in the docs.

In the docs it states:

"The parser shall not invoke this method until it has either abandoned
 parsing (because of an unrecoverable error) or reached the end of input."

The confusion for me arises because the occurrence of a fatal error
does not imply that an exception has to be thrown, only that it is
reported to the error handler. And when an exception is thrown
in a non-fatal case, then one cannot say that the parser has abandoned
parsing, but rather that the application did it.

The normal way is: If *I* make a function call that throws an exception 
then *I* have to write the "finally" clause to do the clean up. 
A library that provides an implicit finally does the unexpected thing.

Karl
(Continue reading)


Gmane