Styrow.dev
Question 209 of 247
Java Topic: General medium

What is the use of finally block?

Question

What is the use of finally block?

Answer

The finally block encloses code that is always executed at some point after the try block, whether an exception was thrown or not. This is right place to close files, release your network sockets, connections, and perform any other cleanup your code requires. Note:If the try block executes with no exceptions, the finally block is executed immediately after the try block completes. It there was an exception thrown, the finally block executes immediately after the proper catch block completes