MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 306

Developing coldfusion mx applications
Table of Contents

Advertisement

Reviewing the code
The following table describes the code:
Code
<cfset EmpID=3>
<cfparam name="errorCaught" default="">
<cftry>
<cfquery name="test"
datasource="CompanyInfo">
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>
<cfcatch type="MissingInclude">
<h1>Missing Include File</h1>
<cfoutput>
<ul>
<li><b>Message:</b> #cfcatch.Message#
<li><b>Detail:</b> #cfcatch.Detail#
<li><b>File name:</b>
#cfcatch.MissingFilename#
</ul>
</cfoutput>
<cfset errorCaught = "MissingInclude">
</cfcatch>
306
Chapter 14: Handling Errors
Description
Initializes the employee ID to a valid value. An
application would get the value from a form or
other source.
Sets the default
errorCaught
the empty string (to indicate no error was
caught).
There is no need to put these lines in a
block.
Starts the
block. Exceptions from here to
cftry
the end of the block can be caught by
tags.
Queries the CompanyInfo database to get the
data for the employee identified by the
variable.
Begins the HTML page. This section contains all
the code that displays information if no errors
occur.
Includes the includeme.cfm page.
Displays the user information record from the
test query.
Handles exceptions thrown when a page
specified by the
cfinclude
Displays
variables, including the
cfcatch
ColdFusion basic error message, detail
message, and the name of the file that could not
be found.
Sets the
variable to indicate the
errorCaught
error type.
variable value to
cftry
cfcatch
EmpID
tag cannot be found.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents