View Havish  Goswami 's Profile
What is the use of the finally block? Is finally block in Java guaranteed to be called? When finally block is NOT called?
Hi Java Professionals,

Please elaborate the answer
Asked by Havish Goswami | Aug 11 2018 | Report this Report abuse
Replies (7)
View Shatish  Rao 's Profile
finally block is used to perform clean-up activities or code clean-up like closing database connection & closing streams or file resources, etc

http://www.benchresources.net/finally-block-in-java-exception-handling/

http://www.benchresources.net/return-statement-with-finally-block-in-java/
Aug 18 2018 | Report this Report abuse
View Chinmay  Hegde 's Profile
finally block is used to perform clean-up activities or code clean-up like closing database connection & closing streams or file resources, etc

http://www.benchresources.net/finally-block-in-java-exception-handling/

http://www.benchresources.net/return-statement-with-finally-block-in-java/
Aug 18 2018 | Report this Report abuse
View Roshan  shah 's Profile
Finally block is used if there is code that must be executed regardless of whether the exception is thrown or not.In the Finally block,clean up code related to closing of database connections,closing of files is written.

Finally block is not called in the conditions mentioned in the above post.
Aug 17 2018 | Report this Report abuse
View Shatish  Rao 's Profile
Finally block is used if there is code that must be executed regardless of whether the exception is thrown or not.In the Finally block,clean up code related to closing of database connections,closing of files is written.

Finally block is not called in the conditions mentioned in the above post.
Aug 17 2018 | Report this Report abuse
View Nirupama  Pathak 's Profile
Finally is the block of code that executes always. The code in finally block will execute even if an exception is occurred. Finally block is NOT called in following conditions

If the JVM exits while the try or catch code is being executed, then the finally block may not execute. This may happen due to System.exit() call.
if the thread executing the try or catch code is interrupted or killed, the finally block may not execute even though the application as a whole continues.
If a exception is thrown in finally block and not handled then remaining code in finally block may not be executed.
Aug 16 2018 | Report this Report abuse
View Nirupama  Pathak 's Profile
Finally block is used to Irrespective of Exception i need to do some logic .i will place such logic into finally block.
finally block always execute except one condition that is if u r placing System.exit(0)

Ex:connection.close()
Aug 16 2018 | Report this Report abuse
View Tanya  Sharma 's Profile
Finally block is used to Irrespective of Exception i need to do some logic .i will place such logic into finally block.
finally block always execute except one condition that is if u r placing System.exit(0)

Ex:connection.close()
Aug 16 2018 | Report this Report abuse