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="exception_handler.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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access