[IronPython] How to get stack traces from runtime exception with using generators.

Dino Viehland dinov at microsoft.com
Fri Aug 21 20:41:25 CEST 2009


Can you include the generator code?  If I do:

using System;
using Microsoft.Scripting.Hosting;
using IronPython.Hosting;

public class Test {
    public static void Main(string[] args) {
        var engine = Python.CreateEngine();

        try {
            engine.Execute(@"
def f():
    raise Exception('hello generator')
    yield 42

def g():
    f().next()

g()
");
        } catch(Exception e) {
            Console.WriteLine(engine.GetService<ExceptionOperations>().FormatException(e));
        }
    }
}

Then this outputs:

Traceback (most recent call last):
  File "<string>", line 7, in g
  File "<string>", line 3, in f
Exception: hello generator

I did use the preferred way to format the exception but they should be equivalent.

> -----Original Message-----
> From: users-bounces at lists.ironpython.com [mailto:users-
> bounces at lists.ironpython.com] On Behalf Of KATO Kanryu
> Sent: Thursday, August 20, 2009 8:09 PM
> To: Discussion of IronPython
> Subject: Re: [IronPython] How to get stack traces from runtime
> exception with using generators.
>
> 2009/8/21 Dino Viehland <dinov at microsoft.com>:
> > Is there a reason you can't just call FormatException for both cases?
>
> OK. I rewrote to the following:
>
> | catch(Exception ex)
> | {
> |     var pythonContext =
> HostingHelpers.GetLanguageContext(pythonEngine) as PythonContext;
> |     Igs.Trace.Error(pythonContext.FormatException(ex));
> | }
>
> But I havn't get stack traces upper the generator yet :(
> _______________________________________________
> 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