Python seems to be ignoring my except clause...

Duncan Booth duncan.booth at invalid.invalid
Tue Feb 19 08:49:16 EST 2008


"Adam W." <AWasilenko at gmail.com> wrote:

> I am trying to handle a Unicode error but its acting like the except
> clause is not even there.  Here is the offending code:
> 
>         def characters(self, string):
>             if self.initem:
>                 try:
>                     self.data.append(string.encode())
>                 except:
>                     self.data.append('No habla la Unicode')
> 
> And the exception:
> 
>   File "C:\Users\Adam\Desktop\XMLWorkspace.py", line 65, in characters
>     try:
> UnicodeEncodeError: 'ascii' codec can't encode character u'\u2026' in
> position 83: ordinal not in range(128)
> 
> Its got to be something really dumb I'm missing, this make no sence.
> 

The example you posted isn't complete and while I can easily expand it to a 
working example it will unfortunately be a working example.

Try cutting it down yourself to a minimal self-contained example that you 
can post. 99% of the time you'll find the problem when you do that and 
avoid having to post at all.

In this case, judging by the stack backtrace quoting the wrong line, I'd 
guess you only just added the try..except and for some reason are still 
executing the old code without the exception handling.



More information about the Python-list mailing list