Exceptions (Handling Small Errors) in Python
Day 10 in #100DaysOfCode
After running our code what we see in the results shows us if our program was successful. We get results looking like this:
Process finished with exit code 0
This means the process was successful. Anything other than zero means that our program has failed.
As Python programmers, we can control The "try and except" method defines what should happen if our program encounters an error instead of crashing the program.
try:
age=int(input('Age: '))
print(age)
except ValueError:
print("Invalid Value")
Result:
Age: Ten
Invalid Value
Process finished with exit code 0
Note that we can add multiple "except" functions for our programs.