Step: Exception handling: try / except
Exception handling: try / except
try:/except ExceptionType: runs code that might fail and recovers instead of crashing the whole program.
Why it matters: real input is messy — try/except lets you skip or handle bad data instead of letting one bad value kill the run.
Example: int("abc") raises ValueError; wrapping it in try/except ValueError lets you handle it gracefully.
Your turn: sum the numeric strings in values, printing a message and skipping any that aren't valid integers.
Pitfall: a bare except: (no type) catches everything, including typos like NameError — always name the specific exception you expect.
Setup:
Your code:Expected output:
Step 15 of 18