Which fix removes the subtle bug?
try:
value = int(raw)
except:
value = 0
- Catch narrowly:
except ValueError: - Catch narrowly:
except Exception as: - Move the assignment above the
try - Add an
else:branch after the except
A bare except also swallows KeyboardInterrupt and real errors; catch the specific one.
Play Problem Solving ▸