What exactly does a finally
block in exception handling perform?
It executes no matter if you get into the catch
block or not, meaning that is a great place for disposing of objects and doing other cleanups.
finally keyword is used just to make sure that code present in finally block must execute in all circumstances irrespective of exception occurances.
for eg:
try{
}
catch(Exception e){
}
finally{
System.out.print("finally executed");
}
Note: In above case finally will always execute.