|
|
The java.rmi.RemoteException is thrown whenever something unexcpected happens while invoking the requested method
on your enterprise bean instance. Usually, these are runtime exceptions that your bean didn't catch,
java.lang.NullPointerException being the most common.
The java.rmi.RemoteException itself is just a wrapper for the real exception. It may have a useful message
associated with it, but it's stack trace is usually worthless to you. To get the most useful output from a
RemoteException, use the error handling code bellow.
try {
myEjb.businessMethod();
} catch (java.rmi.RemoteException re){
System.out.println(re.getMessage());
Throwable realException = re.detail;
realException.printStackTrace();
}
Sometimes, the exception nested inside the java.rmi.RemoteException caught is actually another
java.rmi.RemoteException. A clever strategy to unwrap all the nested RemoteExceptions is to
cycle through them in a while loop as follows. This is the approach the OpenEJB Object Invoker
takes, so if you like the error messages you see here, just copy the this code:
try {
myEjb.businessMethod();
} catch (java.rmi.RemoteException re){
System.out.println(re.getMessage());
Throwable t = re;
while (t instanceof java.rmi.RemoteException) {
t = ((java.rmi.RemoteException)t).detail;
}
t.printStackTrace();
}
|
|