I want to catch an exception, that is nested into another exception. I'm doing it currently this way:
} catch (RemoteAccessException e) {
if (e != null && e.getCause() != null && e.getCause().getCause() != null) {
MyException etrp = (MyException) e.getCause().getCause();
...
} else {
throw new IllegalStateException("Error at calling service 'service'");
}
}
Run Code Online (Sandbox Code Playgroud)
Is there a way to do this more efficient and elegant?