Home / Python / Working with the world

Errors

Errors stop a program unless you catch them. Put risky code in try and handle the problem in except. This matters most for files, which may not exist.

try:
    n = int("abc")
except ValueError:
    print("Not a number")

Test yourself on this