I have this code:
public static void main(String[] args) {
try {
Registry registro = LocateRegistry.getRegistry();
EchoInt stub = (EchoInt) UnicastRemoteObject.exportObject(new EchoObjectRMI(), 0);
bind (or rebind) the stub into the local registry
registro.rebind("echoRemote", stub);
} catch (RemoteException e) {
System.err.println("Something wrong happended on the remote end");
e.printStackTrace();
System.exit(-1); // can't just return, rmi threads may not exit
}
System.out.println("The echo server is ready");
}
}
But when i try to run it the compiler throws this error:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Unreachable catch block for RemoteException. This exception is never thrown from the try statement body
at server.EchoObjectRMI.main(EchoObjectRMI.java:33)
I don’t understand why. In theory, the exportObject method thows the RemoteException exception so, why is saying "This exception is never thrown from the try statement body"?
You need to sign in to view this answers
Leave feedback about this