Which statement about the following program is true?
package mypkg;/*from w w w . j a v a2 s. c om*/ class Exception1 extends Exception {} public class Phone { static void m() throws RuntimeException { throw new ArrayIndexOutOfBoundsException("Call"); } public static void main(String[] messages) { try { m(); } catch (Exception1 e) { throw new RuntimeException("Voicemail"); } finally { throw new RuntimeException("Text"); } } }
D.
The Exception1 is a checked exception since it extends Exception and does not inherit RuntimeException.
The first catch block fails to compile, since the compiler detects that it is not possible to throw this checked exception inside the try block, making Option D the correct answer.
If Exception1 was changed to extend the checked RuntimeException, then the code would compile.