Java | Exception Handling | Question 2

filter_none

edit
close

play_arrow

link
brightness_4
code

class Test extends Exception { }
   
class Main {
   public static void main(String args[]) { 
      try {
         throw new Test();
      }
      catch(Test t) {
         System.out.println("Got the Test Exception");
      }
      finally {
         System.out.println("Inside finally block ");
      }
  }
}

chevron_right


(A)

Got the Test Exception
Inside finally block 

(B)

Got the Test Exception

(C)

Inside finally block 

(D) Compiler Error


Answer: (A)

Explanation: In Java, the finally is always executed after the try-catch block. This block can be used to do the common cleanup work. There is no such block in C++.

Quiz of this Question



My Personal Notes arrow_drop_up