For example, you can use
form to a database. The
Retry the query, so the operation succeeds if the resource was only temporarily unavailable.
1
If the retries fail:
2
Display a custom message to the user
Post the data to an email address so the data could be entered by company staff after the
problem has been solved.
Code that accesses external resources such as databases, files, or LDAP servers where resource
availability is not guaranteed is a good candidate for using try/catch blocks.
Try/catch code structure
In order for your code to directly handle an exception, the tags in question must appear within a
block. It is a good idea to enclose an entire application page in a
cftry
follow the
cftry
exception occurs within the
of exception.
Here is an outline for using
<cftry>
Put your application code here ...
<cfcatch type="exception type1">
Add exception processing code here ...
</cfcatch>
<cfcatch type="exception type2">
Add exception processing code here ...
</cfcatch>
...
<cfcatch type="Any">
Add exception processing code appropriate for all other exceptions
here ...
</cfcatch>
</cftry>
Try/catch code rules and recommendations
Follow these rules and recommendations when you use
•
The
cfcatch
•
You can nest
cftry
<cftry>
code that may cause an exception
<cfcatch ...>
<cftry>
First level of exception handling code
<cfcatch ...>
Second level of exception handling code
</cfcatch
</cftry>
</cfcatch>
</cftry>
300
Chapter 14: Handling Errors
to catch errors in code that enters data from a user registration
cftry
code could do the following:
cfcatch
block with
blocks, which respond to potential errors. When an
cfcatch
block, processing is thrown to the
cftry
and
cftry
tags must follow all other code in a
blocks. For example, the following structure is valid:
to handle errors:
cfcatch
cftry
tag body.
cftry
block. You then
cftry
block for that type
cfcatch
and
tags:
cfcatch
Need help?
Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?
Questions and answers