Used inside a cftry tag. Together, they catch and process
exceptions in CFML pages. Exceptions are events that
disrupt the normal flow of instructions in a CFML page,
such as failed database operations, missing include files, and
developer-specified events.


 catch (any e) { }

Attribute Reference

type string
Default: any

application: catches application exceptions
database: catches database exceptions
template: catches ColdFusion page exceptions
security: catches security exceptions
object: catches object exceptions
missingInclude: catches missing include file exceptions
expression: catches expression exceptions
lock: catches lock exceptions
custom_type: catches the specified custom exception type that is defined in a cfthrow tag
java.lang.Exception: catches Java object exceptions
searchengine: catches Verity search engine exceptions
any: catches all exception types
  • application
  • database
  • template
  • security
  • object
  • missinginclude
  • expression
  • lock
  • custom_type
  • searchengine
  • any

Sample code using the cfcatch tag

Create a divide by zero error and then catch it.

try {
    x = 5/0;
catch (any e) {
    writeOutput("Error: " & e.message);

Expected Result: Error: Division by zero.

Create a divide by zero error and then catch it.

    <cfset x = 5/0 />
    <cfcatch type="any">
        Error: <cfoutput>#cfcatch.message#</cfoutput>

Expected Result: Error: Division by zero.

Signup for cfbreak to stay updated on the latest news from the ColdFusion / CFML community. One email, every friday.

Fork me on GitHub