Updated exception handling for python 3