
248
DEVELOPING
COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Las
t
upda
te
d 8/5/2010
<cferror type="VALIDATION" template="validationerrorhandler.cfm">
•
The ColdFusion default error mechanisms handle any errors that are not handled by the preceding techniques.
These mechanisms include the site-wide error handler that you specify in the ColdFusion Administrator and the
built-in default error pages.
These techniques let you include application-specific information, such as contact information or application or
version identifiers, in the error message, and let you display all error messages in the application in a consistent
manner. You use Application.cfc to develop sophisticated application-wide error-handling techniques, including
error-handling methods that provide specific messages, or use structured error-handling techniques.
Note:
The
onError
method catches errors that occur in the
onSessionEnd
and
onApplicationEnd
application event
methods. It does not display messages to the user, however, because there is no request context. The
onError
function
logs errors that occur when the session or application ends.
Handling server-side validation errors in the onError method
Server-side validation errors are actually ColdFusion exceptions; as a result, if your application uses an
onError
method, this method gets the error and must handle it or pass it on to ColdFusion for handling.
To identify a server-side validation error, search the Arguments.
Exception
.StackTrace field for
coldfusion.filter.FormValidationException. You can then handle the error directly in your
onError
routine, or throw
the error so that either the ColdFusion default validation error page or a page specified by an
cferror
tag in your
Application.cfc initialization code handles it.
Example: error Handling with the onError method
The following Application.cfc file has an
onError
method that handles errors as follows:
•
If the error is a server-side validation error, the
onError
method throws the error for handling by ColdFusion,
which displays its standard validation error message.
•
For any other type of exception, the
onError
method displays the name of the event method in which the error
occurred and dumps the exception information. In this example, because you generate errors on the CFM page
only, and not in a Application.cfc method, the event name is always the empty string.