try:
age = int("twelve")
except ValueError:
print("Please enter digits")Line-by-line explanation
- Try begins the protected block.
- The conversion raises ValueError.
- The matching except block catches it.
- A helpful message is displayed instead of a traceback.
Catch only exceptions you understand and can handle. Unexpected programming bugs should remain visible.