Handling runtime exceptions with ColdFusion tags
307
Using the cfthrow tag
You can use the
cftry
tag to raise your own, custom exceptions. When you use the
cfthrow
tag,
you specify any or all of the following information:
All of these values are optional. You access the attribute values in
cfcatch
blocks and Exception
type error pages by prefixing the attribute with either
cfcatch
or
error
, as in
cfcatch.extendedInfo
. The default ColdFusion error handler displays the message and detail
values in the Message pane and the remaining values in the Error Diagnostic Information pane.
<cfcatch type="Database">
<h1>Database Error</h1>
<cfoutput>
<ul>
<li><b>Message:</b> #cfcatch.Message#
<li><b>Native error code:</b>
#cfcatch.NativeErrorCode#
<li><b>SQLState:</b> #cfcatch.SQLState#
<li><b>Detail:</b> #cfcatch.Detail#
</ul>
</cfoutput>
<cfset errorCaught = "Database">
</cfcatch>
Handles exceptions thrown when accessing a
database.
Displays
cfcatch
variables, including the
ColdFusion basic error message, the error code
and SQL state reported by the databases
system, and the detailed error message.
Sets the
errorCaught
variable to indicate the
error type.
<cfcatch type="Any">
<cfoutput>
<hr>
<h1>Other Error: #cfcatch.Type#</h1>
<ul>
<li><b>Message:</b> #cfcatch.message#
<li><b>Detail:</b> #cfcatch.Detail#
</ul>
</cfoutput>
<cfset errorCaught = "General Exception">
</cfcatch>
Handles any other exceptions generated in the
cftry
block.
Since the error can occur after information has
displayed (in this case, the contents of the
include file), draws a line before writing the
message text.
Displays the ColdFusion basic and detailed error
message.
Sets the
errorCaught
variable to indicate the
error type.
</body>
</html>
</cftry>
Ends the HTML page, then the
cftry
block.
Attribute
Meaning
type
The type of error. It can be a custom type that has meaning only to your
application, such as InvalidProductCode. You can also specify Application, the
default type. You cannot use any of the predefined ColdFusion error types, such
as Database or MissingTemplate.
message
A brief text message indicating the error.
detail
A more detailed text message describing the error.
errorCode
An error code that is meaningful to the application. This field is useful if the
application uses numeric error codes.
extendedInfo
Any additional information of use to the application.
Code
Description
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......