Exception handling allows you to test for and trap exceptions when they happen, so that your applications can respond to problems appropriately, as opposed to just throwing an error or invoking a separate error-handling template. With exception handling, it is usually possible to allow your application to continue functioning despite the fact that an exception has occurred.
Basic exception handling in ColdFusion uses two tags,
cftry
and cfcatch
. These tags
allow you to identify potentially problematic areas of your
application code and deal with anticipated exceptions where they are
most likely to occur. The basic syntax for using
cftry
/cfcatch
is:
<cftry>Potentially problematic code...
<cfcatch type="exception_type
">Code to implement in the event the exception is caught...
</cfcatch> <cfcatch type="exception_type
"> ... </cfcatch> </cftry>