User Guide

210 Chapter 11 Preventing and Handling Errors
</cfcatch>
<!--- Use cfcatch with TYPE="Any" --->
<!--- to find unexpected exceptions. --->
<cfcatch type="Any">
<cfoutput>
<h1>Other Error: #cfcatch.Type#</h1>
<ul>
<li><b>Message:</b> #cfcatch.message#
<li><b>Detail:</b> #cfcatch.Detail#
</ul>
</cfoutput>
</cfcatch>
</cftry>
</body>
</html>
To test the code:
1 Make sure there is no includeme.cfm file and display the page. The cfcatch
type="MissingInclude"
block displays the error.
2 Create a non-empty includeme.cfm file and display the page. If your database is
configured properly you should see an employee entry and not get any error.
3In the
cfquery tag change the line:
FROM Employee
to:
FROM Employer
Display the page. This time the cfcatch type="Database" block displays an
error message
.
4 Correct Employer back to Employee. Change the cfoutput line:
<p>Department: #Dept_ID#<br>
to:
<p>Department: #DepartmentID#<br>
Display the page. This time the cfcatch type="Any" block displays an error
message indicating an expression error.
Custom Exception Types
The type attribute allows a cfthrow tag to throw an exception of a specific type,
which can be caught by a
cfcatch tag that has a matching type attribute.
A
cfthrow tag without a type attribute will throw a type="Application" exception.