<?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="catch"/>
      <!--
           Generated at 2011-12-09T20:47:22.916Z--><title>Saxonica: XSLT and XQuery Processing: saxon:catch</title>
      <meta name="coverage" content="Worldwide"/>
      <meta name="copyright" content="Copyright Saxonica Ltd"/>
      <meta name="title" content="Saxonica: XSLT and XQuery Processing: saxon:catch"/>
      <meta name="robots" content="noindex,nofollow"/>
      <link rel="stylesheet" href="../../saxondocs.css" type="text/css"/>
   </head>
   <body class="main">
      <h1>saxon:catch</h1>
      <p>This instruction is always used together with <code>saxon:try</code>. It is used to catch 
dynamic errors occurring within a <code>saxon:try</code> instruction, and to return an alternative
result when an error occurs.</p>
      <p>The parent instruction must be <code>saxon:try</code>. A <code>saxon:try</code> element must have
at least one <code>saxon:catch</code> child element (there may be several), and the <code>saxon:catch</code>
children must come last, except perhaps for any <code>xsl:fallback</code> children.</p>
      <p>There is a mandatory attribute <code>errors</code> defining which errors are caught. Every error code
is identified by a QName. The attribute is a whitespace-separated list of 
<code>NameTests</code> which are used to match this
QName. Each <code>NameTest</code> may be in the form <code>*</code> (match all names), <code>*:local</code>
(match <code>local</code> within any namespace), <code>err:*</code> (match all names in namespace <code>err</code>,
or <code>err:ABCD9867</code> (match a specific error code). The most common namespace, used by all system-defined
errors, is <code>http://www.w3.org/2005/xqt-errors</code>, for which the conventional prefix is <code>err:</code>.</p>
      <p>The value to be returned by the <code>saxon:catch</code> element may be calculated in an XPath expression
in the <code>select</code> attribute, or in instructions forming the body of the <code>saxon:catch</code> element.</p>
      <p>Within the <code>select</code> expression, or within the body of the <code>saxon:catch</code> element,
the following variables are available. The namespace prefix <code>err</code> in this names must be bound
to the namespace URI <code>http://www.w3.org/2005/xqt-errors</code>.</p>
      <table border="1">
         <thead>
            <tr>
               <td content="para">
                  <p>Variable</p>
               </td>
               <td content="para">
                  <p>Type</p>
               </td>
               <td content="para">
                  <p>Value</p>
               </td>
            </tr>
         </thead>
         <tbody>
            <tr>
               <td content="para">
                  <p>err:code</p>
               </td>
               <td content="para">
                  <p>xs:QName</p>
               </td>
               <td content="para">
                  <p>The error code</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>err:description</p>
               </td>
               <td content="para">
                  <p>xs:string</p>
               </td>
               <td content="para">
                  <p>A description of the error condition</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>err:value</p>
               </td>
               <td content="para">
                  <p>item()*</p>
               </td>
               <td content="para">
                  <p>Value associated with the error. For an error raised by calling the <code>error</code> function,
				this is the value of the third argument (if supplied). For an error raised by evaluating <code>xsl:message</code>
				with <code>terminate="yes"</code>, this is the document node at the root of the tree containing the XML message
				body.</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>err:module</p>
               </td>
               <td content="para">
                  <p>xs:string?</p>
               </td>
               <td content="para">
                  <p>The URI (or system ID) of the stylesheet module containing the instruction where the error occurred;
				an empty sequence if the information is not available.</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>err:line-number</p>
               </td>
               <td content="para">
                  <p>xs:integer?</p>
               </td>
               <td content="para">
                  <p>The line number within the stylesheet module of the instruction where the error occurred;
				an empty sequence if the information is not available.</p>
               </td>
            </tr>
            <tr>
               <td content="para">
                  <p>err:column-number</p>
               </td>
               <td content="para">
                  <p>xs:integer?</p>
               </td>
               <td content="para">
                  <p>The column number within the stylesheet module of the instruction where the error occurred;
				an empty sequence if the information is not available.</p>
               </td>
            </tr>
         </tbody>
      </table>
      <p>The catch block can throw a new error by calling the <code>error()</code> function.</p>
      <p>Variables declared within the <code>saxon:try</code> block are not visible within the
<code>saxon:catch</code> block.</p>
      <p>For examples, see <a class="bodylink" href="../../extensions/instructions/try-instr.xml">saxon:try</a>.</p>
      <table width="100%">
         <tr>
            <td>
               <p align="right"><a class="nav" href="collation.xml">Next</a></p>
            </td>
         </tr>
      </table>
   </body>
</html>