How can I get a service specific exception with a String-argument
constructor to be catch-able in my client with the message intact?

I have a service with a method from which I want to throw a service-specific
exception with a message, i.e. the exception constructor has a String
argument:

class MyException extends Exception {
  MyException(String s) {super(s);}
}

In my client app, I want to catch MyException, and print the message:

try {
  myService.myMethod();
} catch (MyException e) {
  System.out.println("caught MyException, msg is " + e.getMessage());
} catch (AxisFault) af) { /* FIXME this is for debugging */
  System.out.println("caught AxisFault, msg is " + e.getMessage());
}

I use java2wsdl, then wsdl2java to generate client stubs.  The generated
client stub for the exception  class extends org.apache.axis.AxisFault
instead of Exception, but I can live with that.  However, when I call my
service's method and it throws MyException("HEY"), the client only can catch
an AxisFault, and not the stub version of MyException.  Plus, the message on
the client is the fully qualified classname of MyException plus the orginal
server-thrown message "HEY".

Changing to having the original exception extend AxisFault made the message
on the client correct, i.e. the classname was gone from the message.  Then,
removing the string-argument constructor enabled the client to directly
catch the specific exception.

So it seems you can't have have your cake and eat it too - either you get
the message on the client and you can't catch the specific exception class,
or you can catch the exception class and you have to forgo the message.

This seems like a bug - am  I missing something?

++++++++++++

I experimented with various combinations of the server-side version of the
service-specific exception:  extends Exception, AxisFault or
RemoteException, has constructor with String argument or doesn't, with the
following results:

Extends     String Constr  Client throws  Client msg

Exception   no             AxisFault      full class name
Exception   yes            AxisFault      full class name + string
AxisFault   no             MyException    null
AxisFault   yes            AxisFault      string
RemoteExcp  no             AxisFault      full class name
RemoteExcp  yes            AxisFault      full class name + string

-- bob

----------
Robert Herold
Cotagesoft, Inc.
650 474 9013 x808


Reply via email to