Should local exceptions be wrapped in RemoteException with RMI?

I am trying to understand the reason why all remote methods have the possibility of throwing a RemoteException.

I am currently doing something like this:publicinterface RemoteReaderextends Remote{

public String readData(File f)throws IOException, RemoteException;

}

Should I be doing something like:publicinterface RemoteReaderextends Remote{

public String readData(File f)throws RemoteException;//no IOException

}

publicclass RemoteReaderImplimplements RemoteReader{

public String readData(File f)throws RemoteException{

try{

//some code that may throw an IOException

}catch (IOException e){

thrownew RemoteException(e.getMessage(), e);

}

}

}

Which is preferred?

[1785 byte] By [RATiXa] at [2007-11-27 8:56:57]
# 1

No. RemoteException should just mean that something went wrong with the transport. Something always can, so RMI obliges you to declare RemoteException as thrown by every remote method. You should use your own exception classes for your own exceptions, then you'll have an easy way of distinguishing application problems from platform problems.

ejpa at 2007-7-12 21:20:46 > top of Java-index,Java Essentials,Java Programming...
# 2
Thank you. It's just that I have seen people do it the second way and I was wondering if I should change my code.
RATiXa at 2007-7-12 21:20:46 > top of Java-index,Java Essentials,Java Programming...
# 3
You can do it either way but I like your code the way it is, that's what I do. RemoteException just for the transport, never throw it myself. Methods also throw IOException, my exceptions, whatever. Much cleaner.
ejpa at 2007-7-12 21:20:46 > top of Java-index,Java Essentials,Java Programming...