port python 2 exception handling to python 3 syntax