O'Reilly logo

Programming ColdFusion by Rob Brooks-Bilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Error Handling Within the Web-Application Framework

While CFTRY and CFCATCH provide a granular means of handling errors and exceptions within your applications, they can be cumbersome to code. Trying to identify all the potential trouble spots in your applications where CFTRY/CFCATCH code should be placed only compounds the problem. Fortunately, ColdFusion provides a way to handle errors at a more general level. By including ColdFusion’s CFERROR tag within your application’s Application.cfm template, you can implement application-specific “catch all” error handlers.

Although the CFERROR tag can be used in other templates besides Application.cfm, it makes the most sense to use it in this template. The CFERROR tag is generally placed directly below the CFAPPLICATION tag:

<CFAPPLICATION NAME="MyApplication">

<!--- implement error handling --->
<CFERROR TYPE="Exception" TEMPLATE="MyRequestHandler.cfm"
         EXCEPTION="Any" MAILTO="webmaster@example.com">

The CFERROR tag can implement one of four types of error handling, depending on the value specified in the TYPE attribute. The TEMPLATE attribute is also required; it specifies the relative path to a custom error template to execute in the event that an error or exception occurs. Depending on the value specified in the TYPE attribute, different options are available to the error-handling template. Here are the values for TYPE and the corresponding options that are available in the error template:

Exception

Handles a specific exception ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required