Consider the following Java snippets:
try{
//Some code to tryout
}
catch(Exception e){
//Catch if there is an exception
}
finally{
//SNIPPET1 that is always executed
}
The above snippet is essentially equal to
try{
//Some code to tryout
}
catch(Exception e){
//Catch if there is an exception
}
//SNIPPET1 that is always executed
I know that finally block is usually used to close network connections, file streams etc. I do not see a strong motivation in introducing this keyword into the language because one can happily program without using it as well.
Can you please explain the rationale behind introducing this keyword?