Fix exception catching on python 3