Java program to demonstrate the use of finally block
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Exception caught Finally block always get executed kodingwindow@kw:~$
Java program to demonstrate the use of finally block
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Exception caught in the second catch block Finally block always get executed kodingwindow@kw:~$
The following try and finally block sequence is allowed
KW.java
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW Finally block always get executedException in thread "main" java.lang.NullPointerException at KW.main(KW.java:8) kodingwindow@kw:~$
What Next?
Java program to demonstrate the use of nested try, catch, and finally blocks
Java program to handle the ArithmeticException
Java program to handle the NullPointerException
Advertisement