Multiple choice technology programming languages

Do finally block get executed if the exception had not occurred?

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The finally block in exception handling is designed to run regardless of whether an exception occurs or is caught, ensuring cleanup code executes in both success and failure execution paths. Therefore, the statement is true.

AI explanation

To answer this question, let's go through each option to understand why it is correct or incorrect:

Option A) True - This option is correct. The finally block is always executed, regardless of whether an exception occurred or not. It is typically used to release resources or perform cleanup actions that need to be done regardless of the outcome of the try-catch block.

Option B) False - This option is incorrect. The finally block is always executed, even if an exception did not occur.

The correct answer is A) True. This option is correct because the finally block will be executed regardless of whether an exception occurred or not.