Fix exception handler syntax for Python 3 compatibility.
Improve error messages.