*** The str() and unicode() of these exceptions is the same *** * ValueError raised by "int('foo')" repr : ValueError("invalid literal for int() with base 10: 'foo'",) str : invalid literal for int() with base 10: 'foo' unicode: invalid literal for int() with base 10: 'foo' * TypeError raised by "max()" repr : TypeError('max expected 1 arguments, got 0',) str : max expected 1 arguments, got 0 unicode: max expected 1 arguments, got 0 * NameError raised by "foo" repr : NameError("name 'foo' is not defined",) str : name 'foo' is not defined unicode: name 'foo' is not defined * ZeroDivisionError raised by "5/0" repr : ZeroDivisionError('integer division or modulo by zero',) str : integer division or modulo by zero unicode: integer division or modulo by zero * AttributeError raised by "max.foo" repr : AttributeError("'builtin_function_or_method' object has no attribute 'foo'",) str : 'builtin_function_or_method' object has no attribute 'foo' unicode: 'builtin_function_or_method' object has no attribute 'foo' * ImportError raised by "__import__('foobar')" repr : ImportError('No module named foobar',) str : No module named foobar unicode: No module named foobar * IndexError raised by "[][5]" repr : IndexError('list index out of range',) str : list index out of range unicode: list index out of range * OverflowError raised by "int(1e1000)" repr : OverflowError('cannot convert float infinity to integer',) str : cannot convert float infinity to integer unicode: cannot convert float infinity to integer *** The str() and unicode() of these exceptions is the different *** * IOError raised by "open('flooble')" repr : IOError(2, 'No such file or directory') str : [Errno 2] No such file or directory: 'flooble' unicode: (2, 'No such file or directory') * KeyError raised by "{}['foo']" repr : KeyError('foo',) str : 'foo' unicode: foo * SyntaxError raised by "2+*3" repr : SyntaxError('invalid syntax', ('', 1, 3, '2+*3')) str : invalid syntax (, line 1) unicode: ('invalid syntax', ('', 1, 3, '2+*3')) * UnicodeEncodeError raised by "u'\u1234'.encode('ascii')" repr : UnicodeEncodeError('ascii', u'\u1234', 0, 1, 'ordinal not in range(128)') str : 'ascii' codec can't encode character u'\u1234' in position 0: ordinal not in range(128) unicode: ('ascii', u'\u1234', 0, 1, 'ordinal not in range(128)') * UnicodeDecodeError raised by "'Ã'.decode('ascii')" repr : UnicodeDecodeError('ascii', '\xc3', 0, 1, 'ordinal not in range(128)') str : 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128) unicode: ('ascii', '\xc3', 0, 1, 'ordinal not in range(128)')