User Guide

Table Of Contents
Handling runtime exceptions with ColdFusion tags 327
Locking exceptions
The following additional information is available for exceptions related to errors that occur in
cflock tags:
Missing include exceptions
The following additional variable is available if the error is caused by a missing file specified by a
cfinclude tag:
Using the cftry tag: an example
The following example shows the
cftry and cfcatch tags. It uses the cfdocexamples data source,
which many of the examples in this manual use, and a sample included file,
includeme.cfm.
If an exception occurs during the cfquery statement's execution, the application page flow
switches to the
cfcatch type="Database" exception handler. It then resumes with the next
statement after the
cftry block, once the cfcatch type="Database" handler completes.
Similarly, the
cfcatch type="MissingInclude" block handles exceptions raised by the
cfinclude tag.
<!--- Wrap code you want to check in a cftry block --->
<cfset EmpID=3>
<cfparam name="errorCaught" default="">
<cftry>
<cfquery name="test" datasource="cfdocexamples">
SELECT Dept_ID, FirstName, LastName
FROM Employee
WHERE Emp_ID=#EmpID#
</cfquery>
<html>
<head>
<title>Test cftry/cfcatch</title>
</head>
<body>
<cfinclude template="includeme.cfm">
<cfoutput query="test">
<p>Department: #Dept_ID#<br>
Last Name: #LastName#<br>
First Name: #FirstName#</p>
</cfoutput>
Property variable Description
cfcatch.lockName
The name of the affected lock. This is set to "anonymous" if the lock
name is unknown.
cfcatch.lockOperation
The operation that failed. This is set to "unknown" if the failed
operation is unknown.
Property variable Description
cfcatch.missingFileName
The name of the missing file.