Adobe COLDFUSION 9 Manual page 299

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
"Severity","ThreadID","Date","Time","Application","Message"
"Information","web-0","11/20/01", "16:27:08",, "cf_root\runtime\servers\default\logs\
MyAppPage.log initialized"
"Information","web-0","11/20/01","16:27:08",,
"Page: web_root/MYStuff/MyDocs/ cftryexample.cfm Error: MissingInclude"
"Information","web-1","11/20/01","16:27:32",,"
Page: web_root/MYStuff/MyDocs/ cftryexample.cfm Error: "
"Information","web-0","11/20/01","16:27:49",,
"Page: web_root/MYStuff/MyDocs/ cftryexample.cfm Error: Database"
"Information","web-1","11/20/01","16:28:21",,
"Page: web_root/MYStuff/MyDocs/ cftryexample.cfm Error: General Exception"
"Information","web-0","11/20/01","16:28:49",,
"Page: web_root/MYStuff/MyDocs/ cftryexample.cfm Error: "
Reviewing the code
The following table describes the code:
Code
<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>
<cfcatch type="MissingInclude">
<h1>Missing Include File</h1>
<cfoutput>
<ul>
<li><b>Message:</b> #cfcatch.Message#
<li><b>Detail:</b> #cfcatch.Detail#
<li><b>Filename:</b> #cfcatch.MissingFileName#
</ul>
</cfoutput>
<cfset errorCaught = "MissingInclude">
</cfcatch>
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
indicate no error was caught).
There is no need to put these lines in a
Starts the
cftry
block. Exceptions from here to the end of the block can be
caught by
cfcatch
tags.
Queries the cfdocexamples database to get the data for the employee
identified by the
EmpID
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
cannot be found.
Displays
variables, including the ColdFusion basic error message,
cfcatch
detail message, and the name of the file that could not be found.
Sets the
errorCaught
Last updated 8/5/2010
variable value to the empty string (to
block.
cftry
variable.
cfinclude
variable to indicate the error type.
294
tag

Advertisement

Table of Contents
loading

Table of Contents