In some cases, you might want to develop custom errors that control the way that error
CFERROR enables you to specify error pages for four specific types of errors:
You can use the CFERROR tag when you want to create and generate custom error messages from within your ColdFusion application code. Table 9.4 explains the attributes available for use with the CFERROR tag.
Table 9.4. CFERROR Attributes
With CFERROR , you are somewhat limited in the types of errors that you can handle. With the exception of the monitor error type, all the types handled by CFERROR will be caught only when they are not explicitly handled elsewhere in your ColdFusion code. What does this mean? Examine the following example:
<cftry> <cfif NOT isDefined("UserID")> <cfthrow message="I threw an error when I checked for ID"> </cfif> <cfcatch type="any"> An error occurred </cfcatch>
You can see by this example that we are using a CFTRY/CFCATCH block to check whether the UserID value is defined. If it is not, we throw an error, presumably because this value will be required later in the processing.
With the CFTRY/CFCATCH block in place, if the UserID variable doesn't exist, the try/catch error handling will let us know. We then can tell the user this message: "I threw an error when I checked for ID." This alerts the user that a required parameter is missing and that our processing has come to a halt.
Assume that the try/catch error handling block was missing from our code. When our template got to the point where our logic depended on the presence of the UserID variable and it wasn't there, the user would get a messy standard ColdFusion message about an invalid or missing expression.
With CFERROR , even if we have no try/catch code in place, our error would still be caught. Suppose in the application.cfm file of our ColdFusion application that we have added the following line of code:
<cferror type = "REQUEST" template = "defaultError.cfm">
The CFERROR type request acts as a catchall. Thus, when our application found that the UserID variable was missing, it didn't throw the ugly ColdFusion error back to our user. Instead, it presented him or her with the contents of the defaultError.cfm file, which is the template we've specified in our CFERROR statement.
When making use of the
tag, you are given some default
The variables that you have available to you
Table 9.5. Error Variables Returned by CFERROR When the Error Type Is Exception, Request, or Monitor
Table 9.6. Error Variables Returned by CFERROR When the Error Type Is Validation