Question: Write a Java program showing that a method with its own try block does not have to catch every possible error generated within the try.

Write a Java program showing that a method with its own try block does not have to catch every possible error generated within the try. Some exceptions can slip through to, and be handled in, other scopes:

Is my code correct in answering this question? Please help if incorrect.

class newException extends Exception{ public static void exceptionMethod() throws Exception { throw new newException(); } }

public class ExceptionScope { public static void main(String[] args) {

int a = 1; int b = 0;

try { localMethod(); System.out.println("RESULT - " + a / b); } catch (Exception e) { System.out.println(" Exception - Main: " + e); }

}

public static void localMethod() throws Exception { try { System.out.print(" Local Method executes ..."); newException.exceptionMethod(); } catch(Exception e) { System.out.printf(" Exception - localMethod: " + e); } } }

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!