Changed exception handling to conform to python 2.x