Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #64077

Unicode strings as arguments to exceptions

Date 2014-01-16 13:34 +0100
From Ernest Adrogué <nfdisco@gmail.com>
Subject Unicode strings as arguments to exceptions
Newsgroups comp.lang.python
Message-ID <mailman.5586.1389876759.18130.python-list@python.org> (permalink)

Show all headers | View raw


Hi,

There seems to be some inconsistency in the way exceptions handle Unicode
strings.  For instance, KeyError seems to not have a problem with them

>>> raise KeyError('a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: 'a'
>>> raise KeyError(u'ä')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: u'\xe4'

On the other hand ValueError doesn't print anything.

>>> raise ValueError('a')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: a
>>> raise ValueError(u'ä')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError

I'm using Python 2.7.6 on a Unix machine.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Unicode strings as arguments to exceptions Ernest Adrogué <nfdisco@gmail.com> - 2014-01-16 13:34 +0100
  Re: Unicode strings as arguments to exceptions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-01-16 14:16 +0000
    Re: Unicode strings as arguments to exceptions Roy Smith <roy@panix.com> - 2014-01-16 09:32 -0500
    Re: Unicode strings as arguments to exceptions Terry Reedy <tjreedy@udel.edu> - 2014-01-16 18:48 -0500

csiph-web