308
Chapter 14: Handling Errors
Catching and displaying thrown errors
The
cfcatch
tag catches a custom exception when you use any of the following values for the
cfcatch
type
attribute:
•
The custom exception type specified in the
cfthrow
tag.
•
A custom exception type that hierarchically matches the initial portion of the type specified in
the
cfthrow
tag. For more information, see the next section,
“Custom error type name
hierarchy”
.
•
Application
, which matches an exception that is thrown with the
Application
type
attribute or with no
type
attribute.
•
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 cfthrow
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.
Summary of Contents for COLDFUSION MX 61-DEVELOPING COLDFUSION MX
Page 1: ...Developing ColdFusion MX Applications...
Page 22: ...22 Contents...
Page 38: ......
Page 52: ...52 Chapter 2 Elements of CFML...
Page 162: ......
Page 218: ...218 Chapter 10 Writing and Calling User Defined Functions...
Page 250: ...250 Chapter 11 Building and Using ColdFusion Components...
Page 264: ...264 Chapter 12 Building Custom CFXAPI Tags...
Page 266: ......
Page 314: ...314 Chapter 14 Handling Errors...
Page 344: ...344 Chapter 15 Using Persistent Data and Locking...
Page 349: ...About user security 349...
Page 357: ...Security scenarios 357...
Page 370: ...370 Chapter 16 Securing Applications...
Page 388: ...388 Chapter 17 Developing Globalized Applications...
Page 408: ...408 Chapter 18 Debugging and Troubleshooting Applications...
Page 410: ......
Page 426: ...426 Chapter 19 Introduction to Databases and SQL...
Page 476: ...476 Chapter 22 Using Query of Queries...
Page 534: ...534 Chapter 24 Building a Search Interface...
Page 556: ...556 Chapter 25 Using Verity Search Expressions...
Page 558: ......
Page 582: ...582 Chapter 26 Retrieving and Formatting Data...
Page 668: ......
Page 734: ...734 Chapter 32 Using Web Services...
Page 760: ...760 Chapter 33 Integrating J2EE and Java Elements in CFML Applications...
Page 786: ...786 Chapter 34 Integrating COM and CORBA Objects in CFML Applications...
Page 788: ......