What will be the result of compiling and running the following program ?
class Exception1 extends Exception {} class Exception2 extends Exception {} public class ExceptionTest{ public static void main (String [] args) throws Exception{ try{ /*from ww w. j a v a 2s .c o m*/ m2 (); } finally{ m3 (); } } public static void m2 () throws Exception1{ throw new Exception1 (); public static void m3 () throws Exception2{ throw new AnotherExce }
Select 1 option
Correct Option is : A
m2 () throws Exception1, which is not caught anywhere.
But before exiting out of the main method, finally must be executed.
Since finally throw Exception2, the Exception1 thrown in the try block is ignored and Exception2 is thrown from the main method.