User Guide

Table Of Contents
332 Chapter 14: Handling Errors
Any, which matches any exception that is not caught by a more specific cfcatch tag.
Similarly, if you specify any of these types in a
cferror tag, the specified error page will display
information about the thrown error.
Because the
cfthrow tag generates an exception, a Request error handler or the Site-wide error
handler can also display these errors.
Custom error type name hierarchy
You can name custom exception types using a method that is similar to Java class naming
conventions: domain name in reverse order, followed by project identifiers, as in the following
example:
<cfthrow
type="com.myCompany.myApp.Invalid_field.codeValue"
errorcode="Dodge14B">
This fully qualified naming method is not required; you can use shorter naming rules, for
example, just myApp.Invalid_field.codeValue, or even codeValue.
This naming method is not just a convention, however; ColdFusion MX uses the naming
hierarchy to select from a possible hierarchy of error handlers. For example, assume you use the
following
cfthrow statement:
<cfthrow type="MyApp.BusinessRuleException.InvalidAccount">
Any of the following cfcatch error handlers would handle this error:
<cfcatch type="MyApp.BusinessRuleException.InvalidAccount">
<cfcatch type="MyApp.BusinessRuleException">
<cfcatch type="MyApp">
The handler that most exactly matches handles the error. Therefore, in this case, the
MyApp.BusinessRuleException.InvalidAccount handler gets invoked. However, if you used
the following
cfthrow tag:
<cfthrow type="MyApp.BusinessRuleException.InvalidVendorCode
the MyApp.BusinessRuleException handler receives the error.
The type comparison is no case-sensitive.
When to use the cfthrow tag
Use the
cfthrow tag when your application can identify and handle application-specific errors.
One typical use for the
cfthrow tag is in implementing custom data validation. The cfthrow tag
is also useful for throwing errors from a custom tag page to the calling page.
For example, on a form action page or custom tag used to set a password, the application can
determine whether the password entered is a minimum length, or contains both letters and
number, and throw an error with a message that indicates the password rule that was broken. The
cfcatch block handles the error and tells the user how to correct the problem.