Menu

#7 conversion of exception to string fails if non-ASCII message

open
nobody
None
5
2012-12-23
2006-11-02
Anonymous
No

When Python.NET catches a form the CLR code, it tries a
conversion to a string. This conversion fails if the
exception message contains non-ASCII chars(>= 128).

This is particularly bad because with non-english
versions of the .NET framework the exception messages
are localized. (In german, many exception texts contain
"äöü", causing the described error)

Result:
- The user gets an error message of the form
"SomeDotNetExceptionType: <Unprintable exception message>"
- The "testStrOfException" unit test inside
"test_exceptions.py" fails.

Discussion

  • Nobody/Anonymous

    Logged In: NO

    To temporarily get the real exception reason, this
    workaround may help:

    from CLR.System import Exception

    try:
    doSthBad()
    except Exception, e:
    print e.ToString()

     
  • Nobody/Anonymous

    Logged In: NO

    The failing unit test says:

    ======================================================================
    ERROR: Test the str() representation of an exception.
    ----------------------------------------------------------------------
    Traceback (most recent call last):
    File "d:\Projekte\PythonNet\src\tests\test_exceptions.py",
    line 308, in testStrOfException
    self.failUnless(str(e).find('at System.DateTime.Parse')
    > -1)
    UnicodeEncodeError: 'ascii' codec can't encode character
    u'\xfc' in position 34: ordinal not in range(128)

     
  • Nobody/Anonymous

    Logged In: NO

    Comment '2006-11-02 01:37' seems to be wrong. Better method:

    try:
    doSthBad()
    except Exception, e:
    print e.ToString().encode('iso-8859-1', 'ignore')

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.