Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 4 : Exception Handling 3 + 1 0 = 1 3 p t s Consider the following code snippet with exceptions. Note that the
Problem : Exception Handling
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 mainString args
try
try
methodA;
System.out.printlnD;
catch CustomException e
System.out.printlnInner catch: egetMessage;
methodB;
System.out.printlnE;
catch CustomException e
System.out.printlnOuter catch: egetMessage;
public static void methodA throws CustomException
try
methodB;
System.out.printlnC;
throw new CustomException Exception from A;
catch CustomException e
System.out.printlnCatch in A: egetMessage;
throw e;
public static void methodB throws CustomException
throw new CustomExceptionException 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 ie
your Outer catch should only handle the exception from methodA. Write the expected
output from your modified code and explain the changes you made.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started