Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1146

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

Advertisement

DEVELOPING COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Java
double/Double
String
java.util.Date
java.util.List
byte[]
char[]
boolean[]
String[]
java.util.Vector
java.util.Map
Resolving ambiguous data types with the JavaCast function
You can overload Java methods so a class can have several identically named methods. At runtime, the JVM resolves
the specific method to use based on the parameters passed in the call and their types.
In the section The Employee class, the Employee class has two implementations for the SetJobGrade method. One
method takes a string variable, the other an integer. If you write code such as the following, which implementation to
use is ambiguous:
<cfset emp.SetJobGrade("1")>
The "1" could be interpreted as a string or as a number, so no way exists to know which method implementation to
use. When ColdFusion encounters such an ambiguity, it throws a user exception.
The ColdFusion JavaCast function helps you resolve such issues by specifying the Java type of a variable, as in the
following line:
<cfset emp.SetJobGrade(JavaCast("int", "1"))>
The
function takes two parameters: a string representing the Java data type, and the variable whose type you
JavaCast
are setting. You can specify the following Java data types: boolean, int, long, float, double, and String.
For more information about the
Handling Java exceptions
You handle Java exceptions just as you handle standard ColdFusion exceptions, with the cftry and cfcatch tags. You
specify the name of the exception class in the
throws an exception named myException, you specify myException in the
Note: To catch any exception generated by a Java object, specify java.lang.Exception for the
catch any Throwable errors, specify java.lang.Throwable in the
For more information on exception handling in ColdFusion, see
Example: exception-throwing class
The following Java code defines the testException class that throws a sample exception. It also defines a myException
class that extends the Java built-in Exception class and includes a method for getting an error message.
CFML
Real Number
String
Date-time
Comma-delimited list
Array
Array
Array
Array
Array
Structure
function, see the CFML Reference.
JavaCast
tag that handles the exception. For example, if a Java object
cfcatch
Last updated 1/20/2012
tag.
cfcatch
cfcatchtype
tag
attribute.
cfcatch
type
"Handling
Errors" on page 275.
1141
attribute. To

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents