User Guide

Table Of Contents
Defining the application and its event handlers in Application.cfc 291
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 MX, 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.
<cfcomponent>
<cfset This.name = "BugTestApplication">
<cffunction name="onError">
<!--- The onError method gets two arguments:
An exception structure, which is identical to a cfcatch variable.
The name of the Application.cfc method, if any, in which the error
happened.
<cfargument name="Except" required=true/>
<cfargument type="String" name = "EventName" required=true/>
<!--- Log all errors in an application-specific log file. --->
<cflog file="#This.Name#" type="error" text="Event Name: #Eventname#" >
<cflog file="#This.Name#" type="error" text="Message: #except.message#">
<!--- Throw validation errors to ColdFusion for handling. --->
<cfif Find("coldfusion.filter.FormValidationException",
Arguments.Except.StackTrace)>
<cfthrow object="#except#">
<cfelse>
<!--- You can replace this cfoutput tag with application-specific
error-handling code. --->
<cfoutput>
<p>Error Event: #EventName#</p>
<p>Error details:<br>
<cfdump var=#except#></p>
</cfoutput>
</cfif>
</cffunction>
</cfcomponent>
To test this example, put a CFML page with the following code in the same page as the
Application.cfc file, and enter valid and invalid text in the text input field.
<cfform>
This box does Integer validation:
<cfinput name="intinput" type="Text" validate="integer"
validateat="onServer"><br>
Check this box to throw an error on the action page:
<cfinput type="Checkbox" name="throwerror"><br>
<cfinput type="submit" name="submitit">
</cfform>