Handling runtime exceptions with ColdFusion tags
301
If an exception occurs in the first level of exception-handling code, the inner
cfcatch
block
can catch and handle it. (An exception in a
cfcatch
block cannot be handled by
cfcatch
blocks at the same level as that block.)
•
ColdFusion always responds to the latest exception that gets raised. For example, if code in a
cftry
block causes an exception that gets handled by a
cfcatch
block, and the
cfcatch
block
causes an exception that has no handler, ColdFusion will display the default error message for
the exception in the
cfcatch
block, and you will not be notified of the original exception.
•
If an exception occurs when the current tag is nested inside other tags, the CFML processor
checks the entire stack of open tags until it finds a suitable
cftry/cfcatch
combination or
reaches the end of the stack.
•
Use
cftry
with
cfcatch
to handle exceptions based on their point of origin within an
application page, or based on diagnostic information.
•
The entire
cftry
tag, including all its
cfcatch
tags, must be on a single ColdFusion page. You
cannot put the
<cftry>
start tag on one page and have the
</cftry>
end tag on another page.
•
For cases when a
cfcatch
block is not able to successfully handle an error, consider using the
cfrethrow
tag, as described in
“Using the cfrethrow tag” on page 309
.
•
If an exception can be safely ignored, use a
cfcatch
tag with no body; for example:
<cfcatch Type = Database />
•
In particularly problematic cases, you might enclose an exception-prone tag in a specialized
combination of
cftry
and
cfcatch
tags to immediately isolate the tag's exceptions.
Exception information in cfcatch blocks
Within the body of a
cfcatch
tag, the active exception’s properties are available in a
cfcatch
object. The following sections describe the object contents.
Standard cfcatch variables
The following table describes the variables that are available in most cfcatch blocks:
Property variable
Description
cfcatch.Detail
A detailed message from the CFML compiler. This message, which can
contain HTML formatting, can help to determine which tag threw the
exception.
The
cfcatch.Detail
value is available in the CFScript
cfcatch
statement as
the
exceptionVariable
parameter.
cfcatch.ErrorCode
The
cfthrow
tag can supply a value for this code through the
errorCode
attribute. For
Type="Database"
,
cfcatch.ErrorCode
has the same value as
cfcatch.SQLState
.
Otherwise, the value of
cfcatch.ErrorCode
is the empty string.
cfcatch.ExtendedInfo
Custom error message information. This is returned only to
cfcatch
tags for
which the
type
attribute is
Application
or a custom type.
Otherwise, the value of
cfcatch.ExtendedInfo
is the empty string.
cfcatch.Message
The exception’s default diagnostic message, if one was provided. If no
diagnostic message is available, this is an empty string.
The
cfcatch.Message
value is included in the value of the CFScript
catch
statement
exceptionVariable
parameter.
Summary of Contents for 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: ......