BackUp LevelNext

Generating Custom Error Messages (CFERROR)

ColdFusion displays error pages that can help you to debug your application. There are two types of errors in ColdFusion:

  1. REQUEST -- Request errors occur when a application page is requested and there is an error in the page's code.
  2. VALIDATION -- Validation errors occur when a user violates the form field validation rules during a form submittal.

By default, ColdFusion returns a standard page for these errors. But you may want to customize the error pages that are returned, to make them consistent with the look and feel of your application. Custom error pages also allow you to control the error information that users see, as well as offering work-arounds or ways for users to report the errors.

You set the custom error application pages with the CFERROR tag. You can set the custom error application pages page-by-page, but because custom error pages generally apply to an entire application, it is more efficient to include the CFERROR tag in the Application.cfm file. After you create a custom error page, you must include the CFERROR tag in your application's Application.cfm page.

For information on the syntax of the CFERROR tag, see the CFML Language Reference.

Creating an error application page

The error application page is a file that includes HTML and the parameters associated with the error. The error application page cannot use any CFML tags.

The parameters associated with an error depend on the type of error. All the error parameters use the Error prefix (for example, Error.Diagnostics).

See the CFML Language Reference for more information on the error variables and on using the CFERROR tag.

The following examples show the two types of custom error pages.

Example of a request error

The following example shows a custom error page for a request error:

<HTML>
<HEAD>
    <TITLE>Products - Error</TITLE>
</HEAD>
<BODY>

<CFOUTPUT>
<H2>Sorry</H2>

<P>An error occurred when you requested this page.
Please email the Webmaster to report this error. We 
will work to correct the problem and apologize 
for the inconvenience.</P>

<TABLE BORDER=1>
<TR><TD><B>Error Information</B> <BR>
    #Error.DateTime# <BR>
    #Error.Template# <BR>
    #Error.RemoteAddress# <BR>
    #Error.HTTPRefer#
</TD></TR></TABLE>

</CFOUTPUT>
</BODY>
</HTML>

Example of a validation error

The following example shows a custom error page for a validation error.

<HTML>
<HEAD>
    <TITLE>Products - Error</TITLE>
</HEAD>
<BODY>

<H2>Oops</H2>

<P>You failed to complete all the fields 
in the form. The following problems occurred:</P>

#Error.InvalidFields#

</BODY>
</HTML>

BackUp LevelNext

allaire

AllaireDoc@allaire.com
Copyright © 1998, Allaire Corporation. All rights reserved.