Question: Problem 4 : Exception Handling 3 + 1 0 = 1 3 p t s Consider the following code snippet with exceptions. Note that the

Problem 4: Exception Handling
3+10=13pts
Consider the following code snippet with exceptions. Note that the program execution starts
with main:
public class NestedTryCatch {
static class CustomException extends Exception;
public static void main(String[] args){
try {
try {
methodA();
System.out.println("D");
} catch (CustomException e){
System.out.println("Inner catch: "+ e.getMessage());
}
methodB();
System.out.println("E");
} catch (CustomException e){
System.out.println("Outer catch: "+ e.getMessage());
}
}
public static void methodA() throws CustomException {
try {
methodB();
System.out.println("C");
throw new CustomException ("Exception from A");
} catch (CustomException e){
System.out.println("Catch in A: "+ e.getMessage());
throw e;
}
}
public static void methodB() throws CustomException {
throw new CustomException("Exception from B");
}
}
Write down what will be the output by the given program and briefly justify your
answer.
Modify your code to catch the exceptions thrown by both methodA and methodB,
with the output including but not limited to "Outer catch: Exception from A", i.e
your Outer catch should only handle the exception from methodA. Write the expected
output from your modified code and explain the changes you made.
 Problem 4: Exception Handling 3+10=13pts Consider the following code snippet with

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!