[IronPython] .NET Exception to Python Exception conversion

Michael Foord fuzzyman at voidspace.org.uk
Wed Jun 20 00:45:05 CEST 2007


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:* 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.
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> users mailing list
> users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>   




More information about the Ironpython-users mailing list