1
votes

My RMI server interface declares a method foo() which is declared to throw RemoteException and Exception, as follows:

public interface Node extends RemoteService {

   public void foo() throws RemoteException, Exception;
}

The server implementation is:

public class NodeImpl extends UnicastRemoteObject implements Node {

    public void foo() throws RemoteException, Exception {
      // Implementation - calls other stuff...
    }
}

My client calls foo on the server:

try {
  node.foo();
}
catch (Exception e) {
   System.err.print("Got exception from foo() of type " + e.getClass().getName());
   System.err.println("Exception: " + e.getMessage());
}

Now when I run the client I get:

Got exception from foo() of type java.rmi.UnexpectedException Exception: undeclared checked exception; nested exception is: java.io.InterruptedIOException: The operation timed out

Java doc says this about java.rmi.UnexpectedException:

An UnexpectedException is thrown if the client of a remote method call receives, as a result of the call, a checked exception that is not among the checked exception types declared in the throws clause of the method in the remote interface.

But my remote interface specifies that foo() throws Exception, and java.io.InterruptedIOException is a kind of Exception. So why does my client get UnexpectedException?

Thanks, Tom

2
Your client has caught the exception and is executing the print statements that you have declared, what is the problem? - RossBille
Try to avoid throwing generic exceptions such as Exception. It would better to catch and re-throw these separate exceptions as a domain-specific exception, like ServerException. - Erwin
Please post the full stack trace. Are you sure you have the current version of the code deployed at both the server and the client? and have you restarted the Registry since the last code change? - user207421
Yes, please post the full stack trace. The accepted answer doesn't appear to have answered the question. - Stuart Marks
Unfortunately the full stack trace is what I included in the original post. The target is running an ancient version of the IBM J9 JVM, which JDK1.3 compliant. - user604713

2 Answers

2
votes

But my remote interface specifies that foo() throws Exception, and java.io.InterruptedIOException is a kind of Exception. So why does my client get UnexpectedException

Because

throws Exception 

means the method can throw exception of class type Exception or any of its subclass type. InterruptedIOException is a subclass of Exception so it is perfectly valid for the method to throw InterruptedIOException when in the signature its super type Exception is mentioned.

0
votes

I strongly suspect you aren't running the same version of the code at client and server. Do a clean build and redeploy everything. There seems to be a disagreement between the remote interfaces at server and client.