Open this example in the interactive library
Source code
try:
value = int('not a number')
except ValueError:
print('Invalid integer')Sample output
Invalid integer

Catch a conversion error. A self-contained example using the Python standard library.
Open this example in the interactive library
try:
value = int('not a number')
except ValueError:
print('Invalid integer')Invalid integer