[IronPython] .NET Exception to Python Exception conversion

Dino Viehland dinov at exchange.microsoft.com
Tue Jun 19 15:24:41 PDT 2007


If the exception was raised in Python then you should be able to do:

print event.Exception.Data['PythonExceptionInfo']

which will contain the Python exception object, not that I'm sure you can format that one much better.

What you probably want to do is call PythonEngine.FormatException(event.Exception), for example:

from IronPython.Hosting import PythonEngine

x = PythonEngine()
print x.FormatException(event.Exception)

If you're hosting IronPython then you can use your previously instantiated PythonEngine instead of newing one up just to format an exception.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Laurent Debacker
Sent: Tuesday, June 19, 2007 11:45 AM
To: users at lists.ironpython.com
Subject: [IronPython] .NET Exception to Python Exception conversion

Hello,

I'm catching exceptions raised in my winforms thread using

            def exceptionHandler(sender, event):
                print event.Exception

            Application.ThreadException += ThreadExceptionEventHandler(exceptionHandler)
            Application.SetUnhandledExceptionMode(UnhandledExceptionMode.CatchException)

However the exception I get, contains the long, unintuitive stack trace. How can I convert it to a nice Python exception ?

Regards,
Laurent Debacker.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ironpython.com/pipermail/users-ironpython.com/attachments/20070619/7af1503a/attachment.htm 


More information about the users mailing list