Thread: [Sax-devel] endDocument throwing an exception
Brought to you by:
dmegginson
From: John W. <tu...@wi...> - 2002-05-02 18:29:35
|
"The SAX parser will invoke this method only once, and it will be the last method invoked during the parse. The parser shall not invoke this method until it has either abandoned parsing (because of an unrecoverable error) or reached the end of input" As I understand this endDocument is always called. For example if startDocument throws a SAXException then endDocument will be called before the parser exits. In this case, if endDocument also throws an exception, which of the two exceptions will be thrown by parse()? So given: public void startDocument() throws SAXException { throw new SAXException("starting"); } public void endDocument() throws SAXException { throw new SAXException("ending"); } which exception should I see? My strong preference is for "ending", by the way;) John Wilson The Wilson Partnership http://www.wilson.co.uk |
From: David B. <da...@pa...> - 2002-05-02 23:52:35
|
> "The SAX parser will invoke this method only once, and it will be the last > method invoked during the parse. The parser shall not invoke this method > until it has either abandoned parsing (because of an unrecoverable error) or > reached the end of input" > > As I understand this endDocument is always called. Yes. If it's not, that's a SAX conformance bug. Sadly: last I looked, it wasn't an uncommon bug to omit calling it in the "abandoned parsing" case. That makes it tough to use endDocument() to do things like clean up application state. > For example if > [any callback] throws a SAXException then endDocument will be called before > the parser exits. In this case, if endDocument also throws an exception, > which of the two exceptions will be thrown by parse()? > ... > My strong preference is for "ending", by the way;) Mine too. I'm not sure it'd be right to specify that right now though, unfortunately ... do you know what existing non-buggy parsers do in that situation? I actually think it's bad policy to have that routine throw any exception, but a RuntimeException could always happen. - Dave |
From: Mikael S. <mik...@ho...> - 2002-05-03 21:59:50
|
At 16:48 2002-05-02 -0700, David Brownell wrote: >Mine too. I'm not sure it'd be right to specify that right now >though, unfortunately ... do you know what existing non-buggy >parsers do in that situation? > >I actually think it's bad policy to have that routine throw any >exception, but a RuntimeException could always happen. Is a SAX parser obligated to catch any RuntimeException (in addition to SAXException) and call endDocument afterwards? What about Error:s? |
From: David B. <da...@pa...> - 2002-05-04 15:25:17
|
Well the spec says it'll be invoked when a parser has "abandoned parsing" or "reached the end of input" ... those thrown cases fall into the former category. It's natural to implement this type of constraint in Java by using "try { ... } finally { ... }". - Dave ----- Original Message ----- =46rom: "Mikael St=E5ldal" <mik...@ho...> To: <sax...@li...> Sent: Friday, May 03, 2002 2:25 PM Subject: Re: [Sax-devel] endDocument throwing an exception > At 16:48 2002-05-02 -0700, David Brownell wrote: > >Mine too. I'm not sure it'd be right to specify that right now > >though, unfortunately ... do you know what existing non-buggy > >parsers do in that situation? > > > >I actually think it's bad policy to have that routine throw any > >exception, but a RuntimeException could always happen. > > Is a SAX parser obligated to catch any RuntimeException (in additio= n to > SAXException) and call endDocument afterwards? What about Error:s? > > |