Determining error-handling strategies
293
Handling compiler exceptions
You cannot handle compiler exceptions directly on the page where they occur, because the
exception is caught before ColdFusion starts running the page code. You should fix all compiler
exceptions as part of the development process. Use the reported error message and the code
debugging techniques discussed in
Chapter 18, “Debugging and Troubleshooting Applications,”
on page 389
to identify and correct the cause of the error.
Compiler exceptions that occur on pages you access by using the
cfinclude
or
cfmodule
tags
can actually be handled as runtime errors by surrounding the
cfinclude
or
cfmodule
tag in a
cftry
block. The compiler exception on the accessed page gets caught as a runtime error on the
base page. However, you should avoid this "solution" to the problem, as the correct method for
handling compiler errors is to remove them before you deploy the application.
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 299
.
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 cferror”
on page 294
.
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.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 297
.
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.
Summary of Contents for ColdFusion MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......