exception handling that supports python 3