User Guide

208 Chapter 11 Preventing and Handling Errors
Locking exceptions
The following additional information is available for exceptions related to cflock
sections:
Missing include exceptions
The following additional variable is available if the error is caused by a missing file
specified by a
cfinclude tag:
Exception handling strategies
Use cftry with cfcatch to handle exceptions based on their point of origin within an
application page, or based on diagnostic information.
Use the cftry tag with one or more cfcatch blocks to define a ColdFusion block for
exception handling. When an application page raises an error condition, the
ColdFusion Server checks the stack of currently active blocks for a corresponding
cfcatch handler. In particularly problematic cases, you might enclose an
exception-prone tag in a specialized combination of
cftry and cfcatch to
immediately isolate the tags exceptions, or to use
cftry with cfcatch type="Any" at
a main processing level to gracefully terminate a subsystems processing in case of
an unexpected error.
Exception handling example
The following example shows cftry and cfcatch, using the CompanyInfo data
source used in many of the examples in this book and a sample included file,
includeme.cfm.
If an exception occurs during the cfquery statements execution, the application
page flow switches to the
cfcatch type="Database" exception handler. It then
resumes with the next statement after the
cftry block, once the cfcatch
type="Database" handler completes.
Similarly, the
cfcatch type="MissingInclude" block handles exceptions raised by
the
cfinclude tag. Any unknown, but possibly recoverable, exceptions are handled
by the
cfcatch type="Any" block.
Property variable Description
cfcatch.lockName
The name of the affected lock. This is set to
"anonymous" if the lock name is unknown.
cfcatch.lockOperation
The operation that failed. This is set to "unknown" if the
failed operation is unknown.
Property variable Description
cfcatch.missingFileName
The name of the missing file.