~/ learn/ comp-348/ cards/ Java RMI
1 of 25

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

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/0a211fb2-017c-46e5-89b1-d8698ca35a93/flashcard utf-8 LF