Being a novice in this this, what's the benefits of using the finally
clause in exception handling. Or in otherwords, when it's best to use it and when it's best not use it.
The only one that I can think of is closing an input/output stream ...any other benefits ???!!
Whatever StinePike has written is perfect but I want to add something in that.
Finally block is executed either exception occurs or not.... so we can achieve this without finally block by writing the finally block code in try block and also in catch block(). Now if exception doesn't occur, it execute the code from try block.If exception occurs, it execute the code from catch block.
So the additional advantage from the finally block is that you can write return statement anywhere in the method, still finally block is executed but the code is not executed if you don't write the code in finally block and return from the method(on the basis of some condition) before reaching to that code.