相关疑难解决方法(0)

Catching an exception that is nested into another exception

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?

java exception try-catch nested-exceptions

26
推荐指数
4
解决办法
4万
查看次数

标签 统计

exception ×1

java ×1

nested-exceptions ×1

try-catch ×1