[IronPython] Stack Traces in IronPython 0.96 do not contain python stack trace

Martin Maly Martin.Maly at microsoft.com
Wed Dec 14 18:17:22 CET 2005


When you catch the exception after g.Call(...), do you also examine the exception's CallStack?

I tried simpler variation on your code:

try {
    engine.Import("x");
    Function f = engine.Evaluate("x.f") as Function;
    f.Call();
} catch (Exception x) {
    output.write(x.ToString());
    output.write(x.StackTrace);
}

Where x.py is:

def f():
    return 1/0

And I got following output:

x.ToString():
Attempted to divide by zero.

x.StackTrace:
   at IronPython.Objects.IntOps.Divide(Int32 x, Int32 y) in d:\Ip\IronPython\Src\IronPython\Objects\IntOps.cs:line 169
   at IronPython.Objects.IntOps.FloorDivide(Int32 x, Object other) in d:\Ip\IronPython\Src\IronPython\Objects\IntOps.cs:line 382
   at IronPython.Objects.IntOps.Divide(Int32 x, Object other) in d:\Ip\IronPython\Src\IronPython\Objects\IntOps.cs:line 164
   at IronPython.Objects.Ops.Divide(Object x, Object y) in d:\Ip\IronPython\Src\IronPython\Objects\Ops.cs:line 866
   at x.f$f0() in D:\Ip\IronPython\Presentations\Editor\bin\Debug\x.py:line 2
   at IronPython.Objects.Function0.Call() in d:\Ip\IronPython\Src\IronPython\Objects\Function.cs:line 50
   at Editor.Editor.RunScript(Object sender, EventArgs e) in D:\Ip\IronPython\Presentations\Editor\Editor.cs:line 45

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Stanislas Pinte
Sent: Wednesday, December 14, 2005 1:17 AM
To: users at lists.ironpython.com
Subject: [IronPython] Stack Traces in IronPython 0.96 do not contain python stack trace

hello,

Has anyone an idea of the following:

I have a script:

> #ScriptingLoopTest python code
> 
> def init_session(settings, fileNamePrefix):
>   pass
> 
> def handle_message(message):
>   passmmm

and I use IronPython 0.96 as embedded scripting engine.

private PythonEngine engine = new PythonEngine();
engine.Import(moduleName);
f = engine.Evaluate(moduleName + ".init_session") as Function;
g = engine.Evaluate(moduleName + ".handle_message") as Function;

when I do g.Call(...), IP detects that the passmm  symbol is not
defined, and throws a PythonException.

This exception only contains that:

"name 'passmmm' not defined".

It doesn't contain the line number in the imported script, nor the
trace, whereas Python 2.4 gives the following:

Python 2.4.2 (#67, Sep 28 2005, 12:41:11) [MSC v.1310 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def handle_message(message):
..     passmmm
..
>>> handle_message(3)
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 2, in handle_message
NameError: global name 'passmmm' is not defined
>>>

It is very important for me to be able to give the user that kind of
feedback...is there a way to do it?

Thanks a lot,

Stan.


_______________________________________________
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