Fix a Python 3 exception handling bug.