InterviewSolution
Saved Bookmarks
| 1. |
Is try without a catch allowed in Java? |
|
Answer» The TRY, catch and finally blocks are used for exception handling. The try block is allowed without a catch block in Java but the finally block should be PROVIDED. The finally block always executes whether there is an exception or not in the try block. The only time it does not execute is if System.exit() is called. A program that demonstrates the try without a catch block is Java is GIVEN as follows: PUBLIC class Demo { public static void MAIN(String args[]) { try { System.out.println("The try block"); } finally { System.out.println("The finally block"); } } }The output of the above program is as follows: The try block The finally block |
|