This is a silly question I am putting here ,I got confused with the basic try catch logic;
please check the code I wrote above.
it gives output 1234
and if I remove finally block from above code ,output is 124.
As far as I remember finally is used to execute important code(cleanup ,message to user etc..) even if there is an exception.
but above code print 4 in both the cases (with /without finally).then whats the use of finally .
guys I think I am missing very basic concept of exception handling. please help.
Hello Shashank, well you placed a println statement in the finally block and it executes the statement and displays 3 in the output as expected.
In java when you handle an exception, the program executes to completion. Why?...well simply because the catch block took care of the problem and it was NOT propagated to the main method to provoke a JVM shut down. HTH.
In Your Pursuit Towards Certification, NEVER Give Up.