<?xml version="1.0" encoding="iso-8859-1"?>
<?xml-stylesheet href="../../make-menu.xsl" type="text/xsl"?><html>
   <head>
      <this-is section="extensions" page="instructions" subpage="try-instr"/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: saxon:try</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: saxon:try"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>saxon:try</h1>
      <p>The <code>saxon:try</code> instruction evaluates an XPath expression in its <code>select</code> 
attribute, or a sequence of child instructions. If any dynamic error occurs while performing this
evaluation, the error may be caught by an <code>xsl:catch</code> instruction that is written as a child
of the <code>xsl:try</code>. For example, the following code catches a failure occurring while executing the
<code>document()</code> function, and returns an <code>&lt;error-document/&gt;</code> element if this
occurs.</p>
      <div class="codeblock"
           style="border: solid thin; background-color: #B1CCC7; padding: 2px">
         <pre>
            <code>
&lt;xsl:variable name="doc" as="document-node()"&gt;
  &lt;saxon:try select="document($input-uri)"&gt;
    &lt;saxon:catch errors="*"&gt;
      &lt;xsl:document&gt;
        &lt;error-document/&gt;
      &lt;/xsl:document&gt;
    &lt;/saxon:catch&gt;
  &lt;/saxon:try&gt;
&lt;/xsl:variable&gt;</code>
         </pre>
      </div>
      <p>The <code>saxon:try</code> element must contain at least one <code>saxon:catch</code> child, and it may
contain several. Each one specifies which errors it is intended to catch in its <code>errors</code> attribute;
the value <code>*</code> catches all errors. The first <code>saxon:catch</code> to match the error code is the
one that is evaluated. The <code>saxon:catch</code> children must come after all other children, with the
exception of any <code>xsl:fallback</code> children (which can be included to define fallback behaviour by processors
that do not recognize the <code>saxon:try</code> instruction.</p>
      <p>The <code>saxon:try</code> element may have either a <code>select</code> attribute, or a sequence of
child instructions (preceding the first <code>xsl:catch</code>); it must not have both.</p>
      <p><i><code>saxon:try</code> is available in Saxon-EE only</i></p>
      <p>See also <a class="bodylink" href="../../extensions/instructions/catch.xml">saxon:catch</a>.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="while.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>