Used with one or more cfcatch tags. Together, they catch and process exceptions in ColdFusion pages. Exceptions are events that disrupt the normal flow of instructions in a ColdFusion page, such as failed database operations, missing include files, and developer-specified events.
Code that might throw an exception One or more cfcatch blocks </cftry>
ColdFusion MX: Changed cfscript to include try and catch statements that are equivalent to the cftry and cfcatch tags.
Within a cftry block, put the code that might throw an exception, followed by one ore more cfcatch tags that catch and process exceptions. This tag requires an end tag.
<cfscript>
myQuery = queryNew("id,name,amount","Integer,Varchar,Integer",
[
{id=1,name="One",amount=15},
{id=2,name="Two",amount=18},
{id=3,name="Three",amount=32}
]);
</cfscript>
<cftry>
<cfloop query = "myQuery">
<!--- Use a non-existent column --->
<cfoutput>#location#</cfoutput>
</cfloop>
<cfcatch type="any">
<p><strong>Incorrect column referred. Please use the correct column.<strong><p>
</cfcatch>
</cftry>
Output
Incorrect column referred. Please use the correct column.
Sign in to your account