有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java客户端收到未声明的检查异常,但异常被声明为已捕获

我的RMI服务器接口声明了一个方法foo(),该方法被声明为引发RemoteException和Exception,如下所示:

public interface Node extends RemoteService {

   public void foo() throws RemoteException, Exception;
}

服务器实现是:

public class NodeImpl extends UnicastRemoteObject implements Node {

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

我的客户端在服务器上调用foo:

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

现在,当我运行客户端时,我得到:

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

Java文档是这样说的。rmi。意外情况:

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.

但我的远程接口指定foo()抛出异常,而java。伊奥。InterruptedIOException是一种异常。那么为什么我的客户会得到意想不到的例外呢

谢谢, 汤姆


共 (0) 个答案