Handling Runtime exception in Java

exception, java

Solution

You could also try following code. This will be better to read and maintain.

try{//do something
}
catch (RuntimeException e) {
    throw e;
} 
catch (Exception e) {
    throw new RuntimeException(e);
}

Problem

I have the following piece of code ``` try{//do something } catch (Exception e) { log.error(e, e); if (e instanceof RuntimeException) { throw (RuntimeException) e; } else { throw new RuntimeException(e); } } ``` the findbugs stataic analysis tool throws this warning on it instanceof will always return true for all nonnull values in methodX, since all RuntimeException are instances of RuntimeException what i dont understand is that its Exception which is being caught and not the RuntimeException, so why this warning ?

Original source