0 votes
in JAVA by
What is finally block?

1 Answer

0 votes
by

The "finally" block is used to execute the important code of the program. It is executed whether an exception is handled or not. In other words, we can say that finally block is the block which is always executed. Finally block follows try or catch block. If you don't handle the exception, before terminating the program, JVM runs finally block, (if any). 

The finally block is mainly used to place the cleanup code such as closing a file or closing a connection. Here, we must know that for each try block there can be zero or more catch blocks, but only one finally block. The finally block will not be executed if program exits(either by calling System.exit() or by causing a fatal error that causes the process to abort).

Related questions

+3 votes
asked May 13, 2021 in JAVA by rajeshsharma
+2 votes
asked May 13, 2021 in JAVA by rajeshsharma
...