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 ...
Get Programming ColdFusion now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.