Used only inside a <cftry>, the cfcatch tag catches and process exceptions.

By specifying the type of error with the type attribute, different types of exceptions can be handled differently.

This tag must have a body.

This tag is also supported within <cfscript>

<cfcatch name=string type=string ><!--- body ---></cfcatch>
Attribute Description
string, optional

The name for the struct containing the exception information

by default it is cfcatch (in Lucee, the cfcatch variable will also be populated)

Alias: variable

string, optional

Type of catch, default:Any


Simple example with cfcatch

  <cfset a = 3/0>
  <cfdump var="#c#" />
    <cfdump var="#cfcatch#">

Nice trick with echo and cfcatch

try {
    throw "demo echo trick";
} catch ( e ){
    echo( e ); // outputs the error nicely using the error template
    echo( cfcatch ); // lucee always populates cfcatch 

See also