Handling Exceptions - MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual

Developing coldfusion mx applications
Table of Contents

Advertisement

Handling exceptions

ColdFusion provides two statements for exception handling in CFScript:
statements are equivalent to the CFML
Note: This section does not explain exception-handling concepts. For a discussion of exception
handling in ColdFusion, see
Exception handling syntax and rules
Exception-handling code in CFScript has the following format:
try {
Code where exceptions will be caught
}
catch(exceptionType exceptionVariable) {
Code to handle exceptions of type exceptionType
that occur in the try block
}
...
catch(exceptionTypeN exceptionVariableN) {
Code to handle exceptions of type
exceptionTypeN that occur in the try block
}
Note: In CFScript,
This structure differs from that of the
When you have a
exceptionVariable variable contains the exception type. This variable is the equivalent of the
tag
cfcatch
cfcatch.Type
Exception handling example
The following code shows exception handling in CFScript. It uses a
create a Java object. The catch statement executes only if the
exception. The displayed information includes the exception message; the except.Message variable
is the equivalent of calling the Java
<cfscript>
try {
emp = CreateObject("Java", "Employees");
}
catch(Any excpt) {
WriteOutput("The application was unable to perform a required
operation.<br>
Please try again later.<br>If this problem persists, contact
Customer Service and include the following information:<br>
#excpt.Message#<br>");
}
</cfscript>
Chapter 14, "Handling Errors," on page
statements follow the
catch
cftry
statement, you must have a
try
built-in variable.
getMessage
and
tags.
cftry
cfcatch
block; you do not put them inside the
try
tag, which must include the
statement. In the
catch
CreateObject
method on the returned Java exception object.
and
try
catch
285.
try
tags in its body.
cfcatch
block, the
catch
function to
CreateObject
function generates an

Handling exceptions

. These
block.
139

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the COLDFUSION MX 61-DEVELOPING COLDFUSION MX and is the answer not in the manual?

Questions and answers

Subscribe to Our Youtube Channel

This manual is also suitable for:

Coldfusion mx

Table of Contents