开发者

Cannot cast from Throwable to MyException

开发者 https://www.devze.com 2023-01-25 15:24 出处:网络
I am catchi开发者_运维问答ng an Exception and trying to examine the getCause() of it, performing some further actions if the cause is a of type MyException, defined in another library.

I am catchi开发者_运维问答ng an Exception and trying to examine the getCause() of it, performing some further actions if the cause is a of type MyException, defined in another library.

I am getting this Eclipse (compiler?) error when trying to check if e.getCause() instanceof MyException:

Incompatible conditional operand types Throwable and MyException

When attempting to cast (MyException) e.getCause(), I get:

Cannot cast from Throwable to MyException

I can compiled e.getCause().getClass().equals(MyException.class), and this does return true.


The solution is that MyException inherited from an Exception in an external library, but the top-level project didn't include that external library. I discovered this when I created a private class that extended MyException, and got an inconsistent type hierarchy error.

0

精彩评论

暂无评论...
验证码 换一张
取 消