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.
from __future__ import print_function def read_file(f): print("before " + f) try: with open(f, 'r') as fh: pass # do something with the file... except Exception: print(" Could not open " + f) print("after " + f) # 3 of the 4 file exist files = 'one.txt', 'zero.txt', 'two.txt', 'three.txt' for f in files: read_file(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