RE: [xsl] Java exception handling in XSLT is possible (and darn useful!)

Subject: RE: [xsl] Java exception handling in XSLT is possible (and darn useful!)
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 3 Dec 2002 10:17:17 -0000
> Hi, I have code I'm willing to share. This code implements 
> Java exception handling in XSLT for Saxon and Saxon v7.

I think that what's really needed is a mechanism that handles all
dynamic errors, not only those that come from extension functions.
Dynamic errors are going to be much more common with XSLT 2.0 / XPath
2.0 than they were with 1.0, because the philosophy of defining a
recovery fallback for every error condition has changed.

We spent some time trying to define a general try/catch mechanism in
XPath 2.0 and decided to leave it out (influenced for once by the
clamour to keep the language simple).

Some of the difficulties in specifying and implementing a general
try/catch are:

* When you catch an error, do you rollback all changes to the result
tree made by that try block? If not, what guarantees do you have about
the state of the result tree after the catch?

* Is lazy evaluation allowed to trigger errors inside the try block when
evaluating constructs that appeared textually outside it, and vice
versa?

* How does try/catch interact with the mechanism allowing processors to
recover from dynamic errors?

* How does try/catch interact with the JAXP mechanism for notifying
errors to an ErrorListener?

I would be interested to know how you have addressed these questions in
your Saxon extension.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 



 Here 
> is an example (given the namespace prefix "ex" is define with 
> the URL 
> http://regenstrief.org/org.regenstrief.saxon7.>
ExceptionElementFactory
> the thing works as follows:
> 
>    <ex:try>
>       <!-- do something that could fail -->
> 
>      <ex:catch exception="java.lang.NullPointerException">
>        <xsl:message terminate="no">
>          <WARNING exception="{ex:current-exception()}"/>
>        </xsl:message>
>      </ex:catch>
>      <ex:catch exception="my.package.ReallyBadException">
>        <ex:throw select="ex:current-exception()"/>
>      <ex:catch>
>    <ex:try>
> 
> and you can have more ex:catch blocks inside the ex:try 
> element to get particular types of exceptions (specified as 
> java fully qualified class names in ex:catch/@exception attribute.
> 
> If you want to use this code, please respond to the list in 
> public (I want a public show of hands.) I am glad to share 
> the code, but I would prefer to integrate it into Saxon or 
> any other XSLT package (I suppose it's quite easy to transfer 
> into Xalan -- just haven't had the time to worry about Xalan 
> and it's internals) instead of a free-floating snippet.
> 
> best regards,
> -Gunther
> 
> -- 
> Gunther Schadow, M.D., Ph.D.                    
> gschadow@xxxxxxxxxxxxxxx
> Medical Information Scientist      Regenstrief Institute for 
> Health Care
> Adjunct Assistant Professor        Indiana University School 
> of Medicine
> tel:1(317)630-7960                         
> http://aurora.regenstrief.org
> 
> 
> 
>  XSL-List info and archive:  
> http://www.mulberrytech.com/xsl/xsl-list
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread