The code below will throw a RuntimeException which will be caught by the first catch block that handles the RuntimeException. Then
why is it that the second catch block is attempting to handle the RuntimeException. Is it because a RuntimeException and an ArithmeticException are both unchecked exception?.

public class Tester {
public static void main(String[] args) {
try {
throw new RuntimeException();
} catch (RuntimeException e) {
System.out.println("RuntimeException");
} catch (ArithmeticException e) {
System.out.println("ArithmeticException");
} catch (Exception e) {
System.out.println("Exception");
}
}
}

Okay. So what's wrong?

The try block, as posted, doesn't even compile, bacause, with the point we just illuminated above, the ArithmeticException block is an unreachable block of code which is, then, uncompilable.

So, what's the actual, compilable code look like, and what's your problem with it?

Okay, but you claimed that the second block was catching the exceptions, and, in fact, the code doesn't even compile, so on what were you basing your supposition?

This article has been dead for over six months. Start a new discussion instead.