378
Exception handling
You can catch exceptions thrown by the CORBA object methods with the
cfcatch
Calling Java Objects
The
on the ColdFusion Administrator JVM and Java Settings page. For example:
<cfobject type="Java" class="MyClass" name="myObj">
Although this tag loads the class, it does not create an instance object. Static
methods and fields are accessible after the call to
To call the constructors explicitly, use the
arguments; for example:
<cfset ret=myObj.init(arg1, arg2)>
If you call a public method on the object without first calling the
result is an implicit call to the default constructor.
Arguments and return values can be any valid Java type; for example, simple arrays
and objects. ColdFusion does the appropriate conversions when strings are passed
as arguments, but not when they are received as return values.
The following sections provide more details on calling Java objects in ColdFusion.
Getting Started with Java
Java is a strongly typed language, unlike ColdFusion, which does not enforce data
types. As a result, there are some subtle considerations when calling Java methods.
The following sections create and use a Java class to illustrate how to use Java
effectively in ColdFusion pages.
Example: the Employee class
The Employee class has four data members: FirstName and LastName are public,
and Salary and JobGrade are private. The Employee class has three overloaded
constructors and a overloaded SetJobGrade method.
Save the following Java source code in the file Employee.java, compile it, and place
the resulting Employee.class file in a directory that is specified in the class path.
public class Employee {
public String FirstName;
public String LastName;
private float Salary;
private int
public Employee() {
tags. However, you cannot extract information from the exception object.
tag can call any Java class that is available on the class path specified
cfobject
JobGrade;
Chapter 20 Using cfobject to Invoke Component Objects
method with the appropriate
init
.
cfobject
init
and
cftry
method, the
Need help?
Do you have a question about the COLDFUSION 5-DEVELOPING and is the answer not in the manual?
Questions and answers