Why do we use finally block?
27 views
- To execute the block if exception occurred
- To execute a code when exception is not occurred
- To execute a code whenever required
- To execute a code with each and every run of program (Correct Answer)
Explanation
Sometimes there is a need to execute a set of code every time the program runs. Even if the exception occurs and even if it doesn’t, there can be some code that must be executed at end of the program. That code is written in finally block. This block is always executed regardless of exceptions occurring.