It's a little bit different, and you don't need to create the PythonEngine (or
at least until we close on that issue :) ), but it's:
import clr
clr.AddReference('IronPython')
from IronPython.Hosting import PythonEngine
PythonEngine.CurrentEngine.FormatException(someException)
We no longer automatically add references to IronPython's dlls which is why you
need the AddReference step as well.
-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Michael Foord
Sent: Tuesday, June 19, 2007 3:45 PM
To: Discussion of IronPython
Subject: Re: [IronPython] .NET Exception to Python Exception conversion
Dino Viehland wrote:
>
> 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)
>
That works! Can you do it with IronPython 2 ? ;-)
Michael Foord
> If you're hosting IronPython then you can use your previously
> instantiated PythonEngine instead of newing one up just to format an
> exception.
>
> *From:* [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] *On Behalf Of *Laurent
> Debacker
> *Sent:* Tuesday, June 19, 2007 11:45 AM
> *To:* [email protected]
> *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.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> users mailing list
> [email protected]
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
_______________________________________________
users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com