User Guide

Table Of Contents
Handling runtime exceptions with ColdFusion tags 331
Using the cfthrow tag
You can use the
cfthrow tag to raise your own, custom exceptions. When you use the cfthrow
tag, you specify any or all of the following information:
All of these values are optional. You access the attribute values in
cfcatch blocks and Exception
type error pages by prefixing the attribute with either
cfcatch or error, as in
cfcatch.extendedInfo. The default ColdFusion error handler displays the message and detail
values in the Message pane and the remaining values in the Error Diagnostic Information pane.
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.
<cfcatch type="Any">
<cfoutput>
<hr>
<h1>Other Error: #cfcatch.Type#</h1>
<ul>
<li><b>Message:</b> #cfcatch.message#
<li><b>Detail:</b> #cfcatch.Detail#
</ul>
</cfoutput>
<cfset errorCaught = "General Exception">
</cfcatch>
Handles any other exceptions generated in the
cftry block.
Since the error can occur after information has
displayed (in this case, the contents of the
include file), draws a line before writing the
message text.
Displays the ColdFusion basic and detailed error
message.
Sets the
errorCaught variable to indicate the
error type.
</body>
</html>
</cftry>
Ends the HTML page, then the cftry block.
Attribute Meaning
type The type of error. It can be a custom type that has meaning only to your
application, such as InvalidProductCode. You can also specify Application, the
default type. You cannot use any of the predefined ColdFusion error types, such
as Database or MissingTemplate.
message A brief text message indicating the error.
detail A more detailed text message describing the error.
errorCode An error code that is meaningful to the application. This field is useful if the
application uses numeric error codes.
extendedInfo Any additional information of use to the application.
Code Description