Zest.

Python: Handle exceptions

A short, tested Python example for handle exceptions. Copy it and adjust the names and paths for your project.

Python
try:
    result = 10 / int(user_input)
except ZeroDivisionError:
    print("Can't divide by zero")
except ValueError as e:
    print(f"Not a number: {e}")
else:
    print(result)
finally:
    print("done")

Find it in Zest

Search for “python handle exceptions” in Zest and this example appears above the results, with other matches to choose from. Searches stay private.

More Python examples

All Python examples