You handle Java exceptions just as you handle standard ColdFusion exceptions, with the cftry and cfcatch tags. You must specify the full class name of the Java exception class in the cfcatch tag that handles the exception. For example, if a Java object throws an exception named myException, you must specify java.lang.exception.myException in the cfcatch tag. 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. 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 myException2(String msg) { super(msg); } public myException2() { super("Error Message from myException"); } } The testException class contains one method, doException, which throws a myException error with an error message. public class testException { public testException () { } public void doException() throws myException { throw new myException("Throwing an exception from testException class"); } } |