I'm implementing a session bean that throws ApplicationException
s.
These exceptions have chained stack traces that may contain exceptions whose classes aren't available on the client. Something like:
@Override
public void doSomethingSpecial(MyObject o) throws MyException {
try {
legacySystem.handle(o);
} catch (LegacyException e) {
logger.warn(e.getMessage(), e);
throw new MyException(e);
}
}
Here it's possible that the client gets an exception it doesn't have the class for. This can result in:
Exception in thread "main" java.lang.reflect.UndeclaredThrowableException
at sun.proxy.$Proxy0.doSomethingSpecial(Unknown Source)
at com.myapp.client.Client.main(Client.java:56)
Caused by: java.lang.ClassNotFoundException: MyLegacyException
I don't want the client to know all the possible exceptions that can be thrown on the server side, but having a stack trace is never bad.
How do you handle these problems? Is it a passable solution to implement an Interceptor
that decouples the stack trace when the exception is sent back to the client? But then the Interceptor
should handle only calls via the RemoteInterface
, because internally I'm interested in the whole stack trace.