Adobe COLDFUSION 9 Manual page 300

Developing applications
Hide thumbs Also See for COLDFUSION 9:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Developing CFML Applications
Code
<cfcatch type="Database">
<h1>Database Error</h1>
<cfoutput>
<ul>
<li><b>Message:</b> #cfcatch.Message#
<li><b>Native error code:</b>
#cfcatch.NativeErrorCode#
<li><b>SQLState:</b> #cfcatch.SQLState#
<li><b>Detail:</b> #cfcatch.Detail#
</ul>
</cfoutput>
<cfset errorCaught = "Database">
</cfcatch>
<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>
</body>
</html>
</cftry>
Using the cfthrow tag
You can use the
tag to raise your own, custom exceptions. When you use the
cfthrow
all of the following information:
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.
All of these values are optional. You access the attribute values in
prefixing the attribute with either
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
tag catches a custom exception when you use any of the following values for the
cfcatch
• The custom exception type specified in the
• A custom exception type that hierarchically matches the initial portion of the type specified in the
more information, see the next section,
, which matches an exception that is thrown with the
Application
attribute.
Description
Handles exceptions thrown when accessing a database.
Displays
cfcatch
the error code and SQL state reported by the databases system, and the
detailed error message.
Sets the
errorCaught
Handles any other exceptions generated in the
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
Ends the HTML page, then the
or
, as in
cfcatch
error
cfcatch.extendedInfo
tag.
cfthrow
Custom error type name
Last updated 8/5/2010
variables, including the ColdFusion basic error message,
variable to indicate the error type.
cftry
variable to indicate the error type.
block.
cftry
cfthrow
blocks and Exception type error pages by
cfcatch
. The default ColdFusion error
cfcatchtype
hierarchy.
attribute or with no
Applicationtype
295
block.
tag, you specify any or
attribute:
tag. For
cfthrow
type

Advertisement

Table of Contents
loading

Table of Contents