What does the 'finally' block in a 'try-except' statement do?
Correct answer
C. It is always executed, regardless of whether an exception occurs
18 views
C. It is always executed, regardless of whether an exception occurs
18 views
The finally block always executes, whether or not an exception occurred — and even if the try block returns early. It is used for clean-up such as closing files or database connections.
The block that runs only when no exception occurs is else, a frequent point of confusion.
Keep preparing with more Computer Science MCQs on MCQsExam.com.
Not sure why the answer is C? Ask here and get an explanation.