SpaceOne added the comment:
I know that UnicodeEncodeError is a subclass of UnicodeError. The problem here
is that UnicodeError would also catch UnicodeDecodeError.
This is especially disturbing if you catch errors of a whole function.
If you e.g. use python2.7 you might want to catch only UnicodeEncodeError if
you encode something and don't want to catch UnicodeDecodeError.
>>> b'\xff'.encode('utf-8')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal
not in range(128)
(Read that code carefully!!! It's not something which should ever be done but
might happen in the world)
Especially if you are writing python2+3 compatible applications.
----------
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25880>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com