Fix old exception syntax that breaks Python 3 compatibility

This patch restores Python 3 compatibility.