Adobe 38043740 - ColdFusion Standard - Mac Development Manual page 1147

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
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
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
from the NetLib library of UDFs from the Common Function Library Project, www.cflib.org. It uses the
class from the standard Java 2 java.net package to get the Internet address of a specified host:
Last updated 1/20/2012
block handles the resulting
cfcatch
function
GetHostAddress
InetAddress
1142

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion 9

Table of Contents