TRY BLOCK WITH CATCH BLOCK AND FINALLY BLOCK IN JAVA in Hindi Lecture 102

//TRY CATCH WITH FINALLY BLOCK 1.Java finally block is a block that is used to execute important code such as a closing connection,stream etc. 2.Java finally block is always executed whether exception is handled or not 3.Java finally block follows try or catch block Syntax---- try { //do something } catch(ExceptionType name) { } catch(ExceptionType name) { } finally { //always executed } //Use of finally block with try-catch block class example { public static void main(String args[]) { try { int c=20/0; System.out.println("c="+c); } catch(ArithmeticException ae) { System.out.println(ae); } finally { System.out.println("Always execute code"); } System.out.println("Remaining code1"); System.out.println("Remaining code2"); } } //Use of finally block with try block and Exception is handled by java class example2 { public static void main(String args[]) { try { int c=20/0; System.out.println("c="+c); } finally { System.out.println("Always executed"); } } }