<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>CFTRY</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">CFTRY</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Used with one or more cfcatch tags. Together, they catch and process exceptions in ColdFusion pages. Exceptions are events that disrupt the normal flow of instructions in a ColdFusion page, such as failed database operations, missing include files, and developer-specified events.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Exception handling tags
</p>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="syntax"><span class="title">Syntax</span><pre>&lt;cftry&gt;
   Code that might throw an exception
   One or more cfcatch blocks
&lt;/cftry&gt;
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">See also</span>
<p>
cfcatch, cferror, cfrethrow, cfthrow, onError; Chapter&#160;14, "Handling Errors" in ColdFusion MX Developer's Guide
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX: Changed cfscript to include try and catch statements that are equivalent to the cftry and cfcatch tags.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
Within a cftry block, put the code that might throw an exception, followed by one ore more cfcatch tags that catch and process exceptions. This tag requires an end tag.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;!--- cftry example, using TagContext to display the tag stack. ---&gt;
&lt;h3&gt;cftry Example&lt;/h3&gt;
&lt;!--- Open a cftry block. ---&gt;
&lt;cftry&gt;
   &lt;!--- Note misspelled tablename &quot;employees&quot; as &quot;employeeas&quot;. ---&gt;
   &lt;cfquery name = &quot;TestQuery&quot; dataSource = &quot;cfdocexamples&quot;&gt;
      SELECT *
      FROM EMPLOYEEAS
   &lt;/cfquery&gt;

   &lt;!--- &lt;p&gt;... other processing goes here ---&gt;
   &lt;!--- specify the type of error for which we search ---&gt;
   &lt;cfcatch type = &quot;Database&quot;&gt;
   &lt;!--- the message to display ---&gt;
      &lt;h3&gt;You&#39;ve Thrown a Database &lt;b&gt;Error&lt;/b&gt;&lt;/h3&gt;
      &lt;cfoutput&gt;
         &lt;!--- and the diagnostic message from the ColdFusion server ---&gt;
         &lt;p&gt;#cfcatch.message#&lt;/p&gt;
         &lt;p&gt;Caught an exception, type = #CFCATCH.TYPE# &lt;/p&gt;
         &lt;p&gt;The contents of the tag stack are:&lt;/p&gt;
         &lt;cfloop index = i from = 1 
               to = #ArrayLen(CFCATCH.TAGCONTEXT)#&gt;
            &lt;cfset sCurrent = #CFCATCH.TAGCONTEXT[i]#&gt;
            &lt;br&gt;#i# #sCurrent[&quot;ID&quot;]# 
               (#sCurrent[&quot;LINE&quot;]#,#sCurrent[&quot;COLUMN&quot;]#) 
               #sCurrent[&quot;TEMPLATE&quot;]#
         &lt;/cfloop&gt;
      &lt;/cfoutput&gt;
   &lt;/cfcatch&gt;
&lt;/cftry&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>

  </body>
</html>
