Adobe COLDFUSION 9 Manual page 293

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Using cftry and cfcatch tags
The
tag lets you go beyond reporting error data to the user:
cftry
• You can include code that recovers from errors so your application can continue processing without alerting the
user.
• You can create customized error messages that apply to the specific code that causes the error.
For example, you can use
cftry
The
code could do the following:
cfcatch
Retry the query, so the operation succeeds if the resource was only temporarily unavailable.
1
2
If the retries fail:
• Display a custom message to the user
• Post the data to an e-mail address so the company staff can enter the data 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
good idea to enclose an entire application page in a
blocks, which respond to potential errors. When an exception occurs within the
the
block for that type of exception.
cfcatch
Here is an outline for using
cftry
<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
tags must follow all other code in a
cfcatch
• You can nest
blocks. For example, the following structure is valid:
cftry
to catch errors in code that enters data from a user registration form to a database.
block. You then follow the
cftry
and
to handle errors:
cfcatch
cftry
tag body.
cftry
Last updated 8/5/2010
cftry
block, processing is thrown to
cftry
and
tags:
cfcatch
288
block. It is a
cftry
block with
cfcatch

Advertisement

Table of Contents
loading

Table of Contents