Catching Multiple Exceptions
You can handle different exception types with multiple except clauses, or group them in a tuple.
You can handle different exception types with multiple except clauses, or group them in a tuple.
try:
value = int(input("Enter a number: "))
result = 100 / value
except ValueError:
print("Not a valid number")
except ZeroDivisionError:
print("Cannot divide by zero")
Order except blocks from most specific to most general.