change how exeptions are handled, so they can be used by python3

I'm using python3 and want to adapt the code to work with it.
I couldn't run any tests on the code yet, but these changes are minor and shouldn't cause any problems with older python versions