User Guide

Table Of Contents
316 Chapter 14: Handling Errors
Handling runtime exceptions
You have many choices for handling exceptions, and the exact path you take depends on your
application and its needs. The following table provides a guide to selecting an appropriate
technique:
Technique Use
cftry
Place cftry blocks around specific code sections where exceptions can be
expected and you want to handle those exceptions in a context-specific manner;
for example, if you want to display an error message that is specific to that code.
Use
cftry blocks where you can recover from an exception. For example, you
can retry an operation that times out, or access an alternate resource. You can
also use the
cftry tag to continue processing where a specific exception will not
harm your application; for example, if a missing resource is not required.
For more information, see “Handling runtime exceptions with ColdFusion tags”
on page 322.
Application.cfc
onError method
Implement the onError method in your Application.cfc to consistently handle
application-specific exceptions that might be generated by multiple code
sections in the application. For more information on error handling using
Application.cfc, see “Handling errors in Application.cfc” on page 290.
cferror with
exception-
specific error
handler pages
Use the
cferror tag to specify error pages for specific exception types. These
pages cannot recover from errors, but they can provide the user with information
about the error’s cause and steps that they can take to prevent the problem.
For more information, see “Specifying custom error messages with the cferror
tag” on page 317.
cferror with a
Request error
page
Use the
cferror tag to specify a Request error handler that provides a
customized, application-specific message for unrecoverable exceptions. Put the
tag in the Application.cfc initialization code or on the Application.cfm page to
make it apply to all pages in an application.
A Request error page cannot use CFML tags, but it can display error variables.
As a result, you can use it to display common error information, but you cannot
provide error-specific instructions. Typically, Request pages display error
variable values and application-specific information, including support contact
information.
For example code, see “Example of a request error page” on page 320.
Site-wide error
handler page
Specify a site-wide error handler in the Administrator to provide consistent
appearance and contents for all otherwise-unhandled exceptions in all
applications on your server.
Like the Request page, the site-wide error handler cannot perform error
recovery. However, it can include CFML tags in addition to the error variables.
Because a site-wide error handler prevents ColdFusion from displaying the
default error message, it allows you to limit the information reported to users. It
also lets you provide all users with default contact information or other
instructions.