How to Throw a Custom Exception in java Services

Hi ,

Couls anyone please tell me if the java service in webmethods support handling of a Custom Exception (other than a ServiceException) . i have encountered a problem wherein i want to close a JMS QueConnection in a java service in finally block . The close connection is throwing an exception ‘javax.jms.JMSException’ . But the throws part(currently only ServiceException) in service signature of the java service cant be edited with
JMS Exception .

IS there any other way out here ?

You cannot change the service signature of a Java Service to throw a specific type of Java Runtime Exception. The Java Service is always designed to throw a ServiceException. However you can handle your own error scenarios within the java service by putting the code in a try catch block. In your case to close the JMS QueueConnection in the finally block, have a try and catch block within the finally block which actually close connections to the JMS Queues and have the catch block throw the specific Runtime Exception.

In addition, you can create your own static classes in the “shared source” area of the java service. Those classes can throw custom exceptions which must be caught by the code in your java service.


What about this? Will this work for you?

if(connection != null)
catch (javax.jms.JMSException jmse) { } // ignore

Or instead of ignoring the exception completely, you could write to the debug log.

Thankx Rob, Mark and Sivaram .The Info was pretty helpful . I guess i will hae to handle the JMS Exception in a seperate try catch block. Thanks once again for timely reply