Java | Exception Handling | Question 2
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
filter_none
(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
Recommended Posts:
- Java | Exception Handling | Question 8
- Java | Exception Handling | Question 4
- Java | Exception Handling | Question 6
- Java | Exception Handling | Question 1
- Java | Exception Handling | Question 7
- Java | Exception Handling | Question 3
- Java | Exception Handling | Question 8
- Nested try blocks in Exception Handling in Java
- Output of Java program | Set 12(Exception Handling)
- Exception Handling with Method Overriding in Java
- C++ | Exception Handling | Question 12
- C++ | Exception Handling | Question 8
- C++ | Exception Handling | Question 7
- C++ | Exception Handling | Question 5
- C++ | Exception Handling | Question 2