
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.
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...