Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 133

Developing applications
Hide thumbs Also See for 38043740 - ColdFusion Standard - Mac:
Table of Contents

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
The CFML Programming Language
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
}
finally {
Code that will execute whether there is an exception or not.
}
Note: In CFScript,
and
catch
structure differs from that of the
When you have a
statement, you must have a
try
contains the exception type. This variable is the equivalent of the
The finally block is optional. Its code always runs, and runs after the code in the try block and any catch block.
Exception handling example
The following code shows exception handling in CFScript. It uses a
The catch statement executes only if the
includes the exception message; the except.Message variable is the equivalent of calling the Java
on the returned Java exception object. The message in the finally block appears after the catch block message.
<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>");
}
finally {
writeoutput("<br>Thank you for visiting our web site.<br>come back soon!");
}
</cfscript>
CFScript example
The following example uses these CFScript features:
• Variable assignment
• Function calls
• For loops
• If-else statements
statements follow the
finally
tag, which must include the
cftry
statement. In the
catch
function generates an exception. The displayed information
CreateObject
Last updated 1/20/2012
block; you do not place them inside the
try
and
cfcatch
cffinally
block, the exceptionVariable variable
catch
tag
cfcatch
cfcatch.Type
function to create a Java object.
CreateObject
128
block. This
try
tags in its body.
built-in variable.
method
getMessage

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents