Changes exception handler to python 3 version

Makes it python 2 and 3 compatible