There are some incompatible changes in code which I depend on. So I want to catch a NoSuchMethodException to log more information about the problem
When I'm using this:
try{
do.something();
}catch(NoSuchMethodException e){
System.out.println("!");
}
I get this error "Unreachable catch block for NoSuchMethodException. This exception is never thrown from the try statement body"
I've tried to catch also java.lang.RuntimeException and check if it's NoSuchMethod but it didn't work.
Reflection will cause performance delays and don't want to use it....
Any ideas?
You was confusing with NoSuchMethodException that is thrown only when invoking method that does not exist using reflection and NoSuchMethodError that may be thrown when you call method directly while this method exists at compile time and does not exist at runtime. It usually happens when using different versions of some external library at compile and runtime.
Bottom line: catch NoSuchMethodError
Catch NoSuchMethodError
instead. However this seems like an ugly workaround and I'd recommend just getting the incompatibility resolved.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With