python 2.5 through 3.4-compatible exception handling