What is the output produced by the following program? What would the output be if the argument to exerciseMethod were 42 instead of 42? (The class NegativeNumberException is defined in Display 9.8,...



What is the output produced by the following program? What would the


output be if the argument to exerciseMethod were −42 instead of 42? (The


class NegativeNumberException is defined in Display 9.8, but you need not


review that definition to do this exercise.)


public class FinallyDemo


{



public static void main(String[] args)



{



try



{



exerciseMethod(42);



}


catch(Exception e)



{



System.out.println("Caught in main.");



}



}



public static void exerciseMethod(int n) throws Exception



{



try



{



if (n > 0)



throw new Exception();



else if (n



throw new NegativeNumberException();



else



System.out.println("No Exception.");



System.out.println("Still in sampleMethod.");



}



catch(NegativeNumberException e)



{



System.out.println("Caught in sampleMethod.");



}



finally



{



System.out.println("In finally block.");



}



System.out.println("After finally block.");



}


}


The class FinallyDemo is on the website that comes with this text.



May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here