What is finally method in Exceptions ?

What is finally method in Exceptions ?

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.


By:Jalees
Date:2011-01-09 00:00:00

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.


By:Sumit Tripathi
Date:2018-05-15 00:00:00

Post Your Answers


User Email:

User Name:
Answers:

Related Java Subjective Links

Java Subjective interview questions and answers for experienced and fresher