modified exception catching statement for compatibility for python 3