Came across this piece of code: -
public <T> T call(final Callable<T> callable) {
try {
return callable.call();
} catch (Exception exception) {
if (exception instanceof RuntimeException) {
throw (RuntimeException) exception; // Line 6
} else {
throw new RuntimeException(exception); // Line 8
}
}
}
- What is the need for doing a
(RuntimeException) exception
at line 6? - What is the difference between the exceptions being thrown at line 6 v/s line 8. Aren't they doing the same thing?