[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Ksoap: how to parse incoming custom exceptions?


Hi,

I'm wondering what is the proper approach for calling a remote method 
that may throw an exception. more specifically, let's say i have a 
remote method:

public ClientInfo getClientInfo(int clientId) throws NoSuchClientException;

ClientInfo and NoSuchClientExceptions are classes i've written, the 
second extends java.lang.Exception. ClientInfo implements 
KvmSerializable and is registered with a ClassMap. The following (or 
something close to it) works fine if method does not throw exception:
try{
ClientInfo cinfo = (ClientInfo) ht.call(urn, methodName);
}
catch(IOException ){}

but, if, for whatever reason, getClientInfo throws 
NoSuchClientException, ht.call throws an IOException. That is not the 
behavior that i'd like to design, because i have other methods that will 
throw more than one exception, and i need to be able to catch them 
separately. So, somehow, i need to be able to cast whatever ht.call 
returns as proper Exception. how do i do that?

I thought of the following:

-have my exception classes implement KvmSerializable (is that 
appropriate - they don't have any bean props)
-register those classes with ClassMap
-Change the above ht.call method to:

Object response = ht.call(stuff)
if(response instance of ClientDetail) {
    cast: (ClientDetail) response}
if(response instanceof NoSuchClientException){
    throw (NoSuchClientException)response;}

That seems logical to me, but it seems that whatever exception the 
remote method throws, ksoap's call method will throw IOException. So if 
that is true, and my above approach won't work, is it possible to 
somehow parse IOException thrown and determine that in fact a 
NoSuchClientException was thrown?

Any other thoughts are more than welcome, of course

thanks a lot
-nikita