Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public static void main(String[ ] args) { try { ExceptionThrowerCode etc = new E

ID: 3877697 • Letter: P

Question

public static void main(String[ ] args)

       {

                 try

                 {

                             ExceptionThrowerCode etc = new ExceptionThrowerCode( );

                             etc.m1( );

                             etc.m2( );

                 }

                 catch (ArithmeticException ae) { ... }

       }

       public class ExceptionThrowerCode

       {

                 ...

                 public void m1( )

                 {

                             ...

                 }

                 public void m2( )

                 {

                             try

                             {

                                       m3( );

                             }

                             catch(ArithmeticException ae) {...}

                             catch(NullPointerException npe) {...}

                 }

                 public void m3( )

                 {

                             try

                             {

                                       ...

                             }

                             catch(ArithmeticException ae) {...}

                 }

       }

If a NullPointerException arises in the try statement in m1

Question 23 options:

it is caught in m2

it is not caught leading to the program terminating

it is caught in m3

it is caught in main

it is caught in m2

it is not caught leading to the program terminating

it is caught in m3

it is caught in main

Explanation / Answer

In the above program NullPointerException arises in the try statement in m1 but when exception occured it checks matching catch block to handle the exception but as in the program there is no appropriate catch block to handle the exception so it is not caught and leads to the termination of the program