Make one coarse-grained remote call and handle the failure a local call cannot have
Make one coarse-grained remote call and handle the failure a local call cannot have
Answer
try { long p = primes.largestPrimeInRange(1000L, 2000L); // one round trip System.out.println("largest prime in [1000, 2000] is " + p); } catch (RemoteException ex) { System.err.println("the call failed: " + ex.getCause()); }
The statement reads exactly like a local call, and that is the point — and the danger. The `catch` is the part that has no local equivalent: it fires when the call never arrived, when the server died mid-call, or when the bytes would not decode, and it cannot tell you which. Print `getCause()` rather than the outer message; the useful text is almost always nested.
JDK javadoc java.rmi