small exception-handling change to support py3 (compatible with py2.6+)