> Apparently this isn't a very good way to go about it because Xalan's
> StylesheetHandler
> class catches this new TransformerException, wraps it in a SAXException,
> which gets
> thrown and makes its way up to the TransformerFactoryImpl which blindly
> takes it as a
> random parsing error. It then gets wrapped in a new TransformerException,
> which is passed
> to the ErrorListener's fatalError method.
I think the idea with ErrorListener#error is that, if the application wants
to try to continue, it should not throw an exception. If it does not throw
an exception, the JAXP 1.1 processor should try to continue as best it
can... if it turns out it can't, it may end up throwing a fatal error
anyway.
The one problem I see in the above scenario is that the exception gets
passed to the ErrorListener twice... once as an error and once as a fatal
error. I'm not sure how realistically clean this up without a
hasBeenReported flag on Transformer exception, or just assuming that all
TransformerExceptions have been reported at the top level... which maybe we
should do, but this gets problematic when you look at it in detail.
The error handling through layers of APIs is painful at best, and the
ambiguity of when to call ErrorListener#error vs. ErrorListener#fatalError
doesn't help much. If someone has a great idea on overhauling the error
handling mechanism in Xalan and making it less painful, I'm all ears.
-scott
Myriam_Midy@lo
tus.com To: [EMAIL PROTECTED]
cc: [EMAIL PROTECTED], (bcc: Scott
Boag/CAM/Lotus)
08/09/01 04:32 Subject: Re: [xsl] Xalan, errors and
ErrorListener
PM
Please respond
to xalan-dev
I am forwarding this question to the xalan list where it really belongs and
one of us will take a look at it. Hopefully you are subscribed to the xalan
list ([EMAIL PROTECTED]).
Myriam
Mike Brown <[EMAIL PROTECTED]>
Sent by: To:
[EMAIL PROTECTED]
[EMAIL PROTECTED] cc:
[EMAIL PROTECTED], (bcc: Myriam
rytech.com Midy/CAM/Lotus)
Subject: [xsl]
Xalan, errors and
ErrorListener
08/09/01 04:12 PM
Please respond to xsl-list
I'm using Xalan 2.2.D6, trying to use my own ErrorListener to nicely format
problems
encountered during stylesheet preparation. I register an instance of the
ErrorListener
implementation with the TransformerFactory, and then I call the factory's
newTemplates
method to get the prepared stylesheet.
My stylesheet intentionally contains a bad attribute name in an
<xsl:template> start tag,
causing the ErrorListener's error method to be invoked.
Both my error and fatalError methods prepare a formatted String using info
in the
TransformerException that is passed into them, and then they throw a new
TransformerException that contains only this String as its message.
Apparently this isn't a very good way to go about it because Xalan's
StylesheetHandler
class catches this new TransformerException, wraps it in a SAXException,
which gets
thrown and makes its way up to the TransformerFactoryImpl which blindly
takes it as a
random parsing error. It then gets wrapped in a new TransformerException,
which is passed
to the ErrorListener's fatalError method.
I tried to look at TransformerFactoryImpl and StylesheetHandler but
couldn't figure out
how it avoids an infinite loop of passing the exception back and forth
between the
factory's newTemplates method and my fatalError method. Yet somehow we get
out of it and
in the end I get a TransformerException with a message saying something
along the lines
of "There was a fatal error. Here it is: There was an error. Here it is:
(...)".
If Xalan's behavior is reasonable, I don't see how I can easily write my
ErrorListener
implementation to distinguish between an error and a fatal error. The fatal
error might
actually be a regular error that has already been reported. Is this really
the way it
should work?
- Mike
____________________________________________________________________________
mike j. brown, fourthought.com | xml/xslt: http://skew.org/xml/
denver/boulder, colorado, usa | personal: http://hyperreal.org/~mike/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list