You never know that the exception will be thrown or not.That means you are not sure that the catch will be executed or not.
So it is better not to put the code inside the catch block which must be executed such as closing a file or a socket connection. Java provide another keyword \'finally\' for this purpose.
The finally block must come immediately after the all catch blocks or after the try block if there is no catch associated with the try block. The finallyblock must be executed, doesn\'t matter the exception is thrown or not.
You never know that the exception will be thrown or not.That means you are not sure that the catch will be executed or not.
So it is better not to put the code inside the catch block which must be executed such as closing a file or a socket connection. Java provide another keyword \'finally\' for this purpose.
The finally block must come immediately after the all catch blocks or after the try block if there is no catch associated with the try block. The finallyblock must be executed, doesn\'t matter the exception is thrown or not.