Let's have a look at how to handle exceptions.
The following example asks the user for input until a valid integer has been entered.
while True:
try:
x = int(input("Please enter a number: "))
break
except ValueError as err:
print("error message: ",err)
print("No valid number. Try again!")
The variable err will be automatically removed after finishing the try except statement.