Finally Return Swallows an Exception
Both functions raise inside try, but only one of them lets that exception escape:
def attempt_a():
try:
raise ValueError("boom")
finally:
return "recovered"
def attempt_b():
try:
raise ValueError("boom")
finally:
print("cleanup ran")
print(attempt_a())
print(attempt_b())
What happens when this runs?
Sign in to answer questions and track your progress
Sign In