Of course in the above example, it would be probably much easier if we just checked if the number was 0, before trying to divide with it. There are many other cases when this is not possible. For example it is impossible to check if open a file will succeed, without actually trying to open the file. When the open() fails, Python throws an IOError exception. So if you have a list of files and you would like to make sure you process as many as possible without any problem caused in the middle, you can catch the exception.

#!/usr/bin/env python
from __future__ import print_function

# 3 of the 4 file exist
files = 'one.txt', 'zero.txt', 'two.txt', 'three.txt'

for f in files:
  print("before " + f)
    fh = open(f, 'r')
    # do something with the file...
  except IOError:
    print("  Could not open " + f)
  print("after  " + f)

# before one.txt
# after  one.txt
# before zero.txt
# after  zero.txt
# before two.txt
#   Could not open two.txt
# after  two.txt
# before three.txt
# after  three.txt