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

Subject: [xsl] Java exception handling in XSLT is possible (and darn useful!)
From: Gunther Schadow <gunther@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 02 Dec 2002 14:14:51 -0500
Hi, I have code I'm willing to share. This code implements Java
exception handling in XSLT for Saxon and Saxon v7. 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


Current Thread