Question: Consider the following code snippet with exceptions. Note that the program execution starts with main: public class NestedTryCatch { static class CustomException extends Exception; public
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 CustomExceptionException 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.Problem pt Consider the following code snippet with exceptions. Note that the main function calls foo in the nested try block. apt Write down what will be printed out by the program and briefly justify your answer. b pt Instead of the "replacement" semantics of exception handling used in modern languages ie the semantics introduced in lecture a very early design of exception handling introduced in the PLI language uses a "binding" semantics. In particular, the design dynamically tracks a sequence of "catch" blocks that are currently active: a catch block is active whenever the corresponding try block is active. Moreover, whenever an exception is thrown. the sequence of active "catch" blocks will be traversed in a firstinlastout manner to find a matching handler. Furthermore, execution will resume at the statement following the one that throws exception, rather than the next statement after the matching "catch" block as we have seen in the "replacement" semantics.Write down what will be printed out by the program if the language uses the "binding" semanties, and briefly justify your answer.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
