Question: Why does the following code output the System.out.println(After the method call);? According to my book, the program should halt after the catch, and goes back

Why does the following code output the System.out.println("After the method call");? According to my book, the program should halt after the catch, and goes back to the main method to execute what's AFTER try and catch block.
public class Test {
public static void main(String[] args) {
try {
method();
System.out.println("After the method call");
}
catch (RuntimeException ex) {
System.out.println("RuntimeException in main");
}
catch (Exception ex) {
System.out.println("Exception in main");
}
}
static void method() throws Exception {
try {
String s ="abc";
System.out.println(s.charAt(3));
}
catch (RuntimeException ex) {
System.out.println("RuntimeException in method()");
}
catch (Exception ex) {
System.out.println("Exception in method()");
}
}
}
Output:
RuntimeException in method() After the method call

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!