Fixed InvalidByteSequenceError exception handling

This is a new attempt at #88, which can now be closed (this one replaces it).