
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.
3
In 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.
Содержание COLDFUSION 5-DEVELOPING
Страница 1: ...Macromedia Incorporated Developing ColdFusion Applications MacroMedia ColdFusion 5 ...
Страница 58: ...38 Chapter 3 Querying a Database ...
Страница 134: ...114 Chapter 7 Updating Your Database ...
Страница 210: ...190 Chapter 10 Reusing Code ...
Страница 232: ...212 Chapter 11 Preventing and Handling Errors ...
Страница 238: ...218 Chapter 12 Using the Application Framework ...
Страница 262: ...242 Chapter 12 Using the Application Framework ...
Страница 278: ...258 Chapter 13 Extending ColdFusion Pages with CFML Scripting ...
Страница 320: ...300 Chapter 15 Indexing and Searching Data ...
Страница 336: ...316 Chapter 16 Sending and Receiving E mail ...
Страница 374: ...354 Chapter 18 Interacting with Remote Servers ...