
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.
Содержание COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Страница 1: ...Developing ColdFusion MX Applications...
Страница 22: ...22 Contents...
Страница 38: ......
Страница 52: ...52 Chapter 2 Elements of CFML...
Страница 162: ......
Страница 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Страница 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Страница 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Страница 266: ......
Страница 314: ...314 Chapter 14 Handling Errors...
Страница 344: ...344 Chapter 15 Using Persistent Data and Locking...
Страница 349: ...About user security 349...
Страница 357: ...Security scenarios 357...
Страница 370: ...370 Chapter 16 Securing Applications...
Страница 388: ...388 Chapter 17 Developing Globalized Applications...
Страница 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Страница 410: ......
Страница 426: ...426 Chapter 19 Introduction to Databases and SQL...
Страница 476: ...476 Chapter 22 Using Query of Queries...
Страница 534: ...534 Chapter 24 Building a Search Interface...
Страница 556: ...556 Chapter 25 Using Verity Search Expressions...
Страница 558: ......
Страница 582: ...582 Chapter 26 Retrieving and Formatting Data...
Страница 668: ......
Страница 734: ...734 Chapter 32 Using Web Services...
Страница 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Страница 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Страница 788: ......
Страница 806: ...806 Chapter 35 Sending and Receiving E Mail...