posted 20 years ago
Hi Rich.
>> I thought I could have, in your terms, XException extend RemoteException, this way client code could directly use XImpl and only have to catch XException.
Actually, for me XException represents one or more application (business or database) exceptions, possibly but not necessarily a superclass of business and database exceptions, anything but RemoteException. I could have said, X1Exception, ..., XnException. But it�s not important. It�s just a raw idea. It�s there to play with and modify. You decided to make it extend RemoteException.
>> Now I find that all code that simply catches XExeption causes errors because RemoteException isn't caught as well. Is this to be expected in this design?
Yes, it is to be expected.
We know for sure that methods of the remote interface must throw RemoteException. Now, why can�t they throw your XException instead? If you look at the API for RemoteException, you will see 19 subclasses. If you declare a method to throw XException, your method cannot throw the other 19 exceptions.
On the server side, your methods wouldn�t throw the other exceptions, because they are your methods, not part of the RMI Runtime. But on the client side, the stub needs to be able to throw those other methods, not just XException.
>> Is your example 3 (wrap RemoteX, hide RemoteException) the only solution to this problem?
It�s the only way I could think of to hide the RemoteException. While coming up with these examples, I was motivated to try to hide the RemoteException. I was also motivated to find simple solutions.
I presented 3 examples. Then I added a 4th example. Then Marcus showed us his solution. Then I added a 5th example. #3 is the only one that hides the RemoteException.
I am not so sure it's important to try to hide that RemoteException (although I did take the opposite view when talking to Marcus above).
>> After taking another look at example 3 makes me think that only this solution will hide the RemoteException.
Yes, I think so.
If you use the �keep option with rmic, you will get the source file for the stub. You will see that the stub implements your methods.
So the object you get from Naming.lookup throws the methods of the remote interface. So that object throws RemoteException. If you want to hide the RemoteException, it seems to me you must wrap the thing you get from Naming.lookup.
----
I am so happy to know my examples made some sense to you and maybe even helped some. Thanks for considering my thoughts.
Marlene
[ August 27, 2004: Message edited by: Marlene Miller ]