Fixed exception handling for Python 3.x

Code is now PEP 3110 compatible.