port exception handling to python2