
1142
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using Web Elements and External Objects
Las
t
upda
te
d 8/5/2010
The myException class has the following code. It throws an exception with a message that is passed to it, or if no
argument is passed, it throws a canned exception.
//class myException
public class myException extends Exception
{
public myException(String msg) {
super(msg);
}
public myException() {
super("Error Message from myException");
}
}
The testException class contains one method, doException, which throws a myException error with an error message,
as follows:
public class testException {
public testException ()
{
}
public void doException() throws myException {
throw new myException("Throwing an exception from testException class");
}
}
Example: CFML Java exception handling code
The following CFML code calls the testException class doException method. The
cfcatch
block handles the resulting
exception.
<cfobject action=create type=java class=testException name=Obj>
<cftry>
<cfset Obj.doException() >
<cfcatch type="myException">
<cfoutput>
<br>The exception message is: #cfcatch.Message#<br>
</cfoutput>
</cfcatch>
</cftry>
Examples: using Java with CFML
The following examples show several examples of using Java objects in CFML. They include examples of using a
custom Java class, a standard Java API class in a user-defined function, a JavaBean, and an Enterprise JavaBean (EJB).
Using a Java API in a UDF
The following example of a user-defined function (UDF) is functionally identical to the
GetHostAddress
function
from the NetLib library of UDFs from the Common Function Library Project,
www.cflib.org
. It uses the
InetAddress
class from the standard Java 2 java.net package to get the Internet address of a specified host:
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...