开发者

Cannot cast from Throwable to MyException

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜