Originally posted by Pete Lyons:
I just had one interface that threw RemoteException in addition to any other exceptions, and documented the fact that these would never be thrown by a local implementation. I was not really happy with this design [...]
Do be happy. This works exactly the way it should do.
The fact that the interface throws RemoteException is an expression of the fact that implementations of this interface
may be Remote. Any code using this interface should not care about the particular implementation it's working with; client code simply needs to cater for the fact that RemoteException may be thrown and doesn't care about whether it can be thrown by the particular implementation or not.
You do not really need to document that RemoteException is never thrown in a local implementation. The code that is using the interface shouldn't even have to know that there
is a local implementation in the first place. Any code that needs a local implementation to work correctly should use Data directly (or perhaps a LocalDataInterface which extends DataInterface and strips all the RemoteExceptions).
By the way, you could argue that the DataInterface methods should all throw IOException rather than RemoteException, to express the fact that socket-based implementations are valid as well as RMI-based ones.
- Peter