In article <[EMAIL PROTECTED]>,
 "Martin v. Löwis" <[EMAIL PROTECTED]> wrote:

> >> I have code like this:
> >> except Exception, e:
> >>    self.setState(self.Failed, str(e))
> >> which fails if the exception contains a unicode argument.
> > 
> > Fails how?
> 
> ASCII encoding error, I suppose. It fails only if a) one argument
> is a Unicode object, and b) that Unicode object contains non-ASCII
> parameters.

Seem ironic that this fails even though pretty nearly anything
else is a valid input to str() -- socket, dict, whatever?

A sort of generic solution might be to follow str's behavior
with respect to '__str__', extending it to fall back to repr()
whatever goes wrong.


    def xtr(a):
        try:
            return str(a)
        except:
            return repr(a)

    ...
        self.setState(self.Failed, xtr(e))

   Donn Cave, [EMAIL PROTECTED]
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to