exception handling converted to Python 3 + PEP 8