Problem Statement
Which order best describes Python's exception flow blocks?
Explanation
Code inside try runs first. If an exception occurs and matches a handler, the matching except runs. If no exception occurs, the else block runs.
The finally block always runs at the end for cleanup, whether an exception happened or not. This ensures resources are released in all cases.
Code Solution
SolutionRead Only
try:
do_work()
except ValueError:
fix()
else:
commit()
finally:
close()