[IronPython] How to get a System.Exception inside a IronPython except: clause

Dino Viehland dinov at exchange.microsoft.com
Wed Jul 9 23:33:32 CEST 2008


Are you getting a TargetInvocationException and trying to get the stack trace of that?  Or is it just some normal exception kind? I'll have to look into why calling FormatException isn't doing the right thing - that info might help...

But anyway, it looks like the Silverlight exception formatter is doing the work it's self - it's just calling .ToString() on the actual .NET exception object.  So I guess I've given you the complicated answer and the simple answer is doing str(myException) + '\n' + myException.clsException.ToString().

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
Sent: Tuesday, July 08, 2008 5:41 PM
To: Discussion of IronPython
Subject: Re: [IronPython] How to get a System.Exception inside a IronPython except: clause

Thanks Dino, That works.

Unfortunately FormatException() doesn't add the CLR stack trace, even
if it has been enabled in silverlight. If the exception is on the main
thread, and if it isn't thrown by the target of an invokation, and you
allow the exception to reach the top of the stack, you can see the CLR
stack trace. I guess for now, when I need to see the CLR stack trace,
the only way around that is to rearrange code so that those conditions
are met.

Is there anything that can (should?) be done about that?

-Dan

On Tue, Jul 8, 2008 at 6:39 PM, Dino Viehland
<dinov at exchange.microsoft.com> wrote:
> There's a clsException property that we add to Python exceptions that will give you the CLR Exception for the corresponding Python Exception.
>
> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Dan Eloff
> Sent: Tuesday, July 08, 2008 4:37 PM
> To: Discussion of IronPython
> Subject: [IronPython] How to get a System.Exception inside a IronPython except: clause
>
> This may sound a little similar to some of my other posts on here, the
> help I received previously has enabled me to get stuck in new and
> exciting areas :)
>
> The stdlib traceback module can be used to format python exceptions,
> but unfortunately it seems to leave out some information, like clr
> exception data (thanks Curt and Jimmy for helping me turn that on). So
> now I find myself thinking how to use
> Application.Current.Environment.GetEngine('py').FormatException()
> (thanks Dino) to do a better job. The only trouble is it wants a clr
> Exception, not a ValueError. Is there any way to call this function
> with the tools available inside of an except: clause ?
>
> Thanks,
> -Dan
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
> _______________________________________________
> Users mailing list
> Users at lists.ironpython.com
> http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
>
_______________________________________________
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