Cannot be thrown from Throwable to MyException

I catch Exception and try to examine its getCause() by following some further steps if cause is of type MyException defined in another library.

I get this Eclipse error (compiler?) When trying to check if e.getCause() instanceof MyException :

Incompatible conditional types of operands Throwable and MyException

When I try to make (MyException) e.getCause() I get:

Cannot be thrown from the Throwable to MyException method

I can compile e.getCause().getClass().equals(MyException.class) and this returns true .

+4
source share
1 answer

The solution is that MyException inherited from Exception in the external library, but the top-level project did not include this external library. I discovered this when I created a private class that extend ed MyException and received an inconsistent type hierarchy error.

+3
source

All Articles