<CFTRY> ... Add code here <CFCATCH TYPE="exceptiontype"> ... Add exception processing code here </CFCATCH> ... Additional CFCATCH blocks go here </CFTRY>
Used with one or more CFCATCH tags, the CFTRY tag allows developers to catch and process exceptions in ColdFusion pages. Exceptions include any event that disrupts the normal flow of instructions in a ColdFusion page such as failed database operations, missing include files, and developer-specified events.
Optional. Specifies the type of exception to be handled by the CFCATCH block:
You must code at least one CFCATCH tag within a CFTRY block. Code CFCATCH tags at the end of the CFTRY block. ColdFusion tests CFCATCH tags in the order in which they appear on the page.
If you specify the type to be ANY, do so in the last CFCATCH tag in the block so that all of the other tests are executed first.
Note: Specifying the type as ANY causes the ColdFusion Application Server to catch exceptions from any CFML tag, data source, or external object, which your application may not be prepared to handle.
Applications can optionally use the CFTHROW tag to raise custom exceptions. Such exceptions are caught with any of the following type specifications:
The custom_type type designates the name of a user-defined type specified with a CFTHROW tag. CFCATCH has a catch handler that can catch a custom type by pattern, providing the custom type is defined as a series of strings concatenated together by periods, as in "MyApp.BusinessRuleException.InvalidAccount". CFCATCH searches for a custom type match starting with the most specific and ending with the least specific. For example, you could define a type as follows:
<CFTHROW TYPE="MyApp.BusinessRuleException.InvalidAccount">
CFCATCH first searches for the entire type string defined in the CFTHROW tag, as follows:
<CFCATCH TYPE="MyApp.BusinessRuleException.InvalidAccount">Then it searches for the next most specific:
<CFCATCH TYPE="MyApp.BusinessRuleException">
Finally, it searches for the least specific:
<CFCATCH TYPE="MyApp">
The order in which you code CFCATCH tags designed to catch a custom exception type within an application does not matter. A CFCATCH tag searches for the custom exception types from most specific to least specific.
If you specify the type to be "APPLICATION, " the CFCATCH tag catches only those custom exceptions that have been specified as having the APPLICATION type in the CFTHROW tag that defines them.
The tags that throw an exception of TYPE="TEMPLATE" are CFINCLUDE, CFMODULE, and CFERROR.
An exception raised within a CFCATCH block cannot be handled by the CFTRY block that immediately encloses the CFCATCH tag. However, you can rethrow the currently active exception by using the CFRETHROW tag.
You can use the CFCATCH variable to access exception information:
Note: In order to see the tag stack displayed by TagContext, use the ColdFusion Administrator to enable the CFML stack trace.Under Debugging in the ColdFusion Administrator, choose the checkbox next to "Enable CFML stack trace. "