changed type checking in exception to be py2 and py3 compatible