[IronPython] Getting a line number of error (RC2)

Dino Viehland dinov at exchange.microsoft.com
Tue Aug 22 17:39:45 CEST 2006


After looking into this a little more I've opened CodePlex bug #2409 to track this.  http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=2409

The issue here is two-fold.  The first is that dynamic methods (which is what we generate under the covers for any code entered at the console) don't have a good debugging story.  They have a great production code story though (in that the GC will collect them).  To make tracebacks work consistently we currently track line number information during code execution (when tracebacks are enabled).  Unfortunately we're not using the line number information that we gather for the trace back to display to the user, instead we just look at the debugging info that we expect to be there for methods.

To get the trace back info from C# code you'll need to call Ops.ExtractException(ex, pythonEngine.Sys);  This will return back to you the raw Python exception (an instance of an old-style class) and you'll be able to call pythonEngine.Sys.exc_info() after that to successfully get the tuple.  Then you should call Ops.ClearException(pythonEngine.Sys); when you're all done to remove the exception info from the current thread as an exception is no longer in flight.

Let me know how well that work around works for you.  If that's acceptable then it seems like we could leave this as a 1.01 bug.

From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Matt Beckius
Sent: Tuesday, August 22, 2006 5:24 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Getting a line number of error (RC2)

Well, I guess since CPython does provide it, I would expect IronPython to.  More importantly, I am embedding IronPython in a hosting app, and I'm trying to accurately report where errors occur.  When an error occurs due to something like I previously outlined, only a ArgumentException is raised (I don't get a line number),  I tried adapting Dino's example by calling pythonEnging.Sys.exc_inf(), but the tuple's 3 memebers are null.

TIA,

MattB


On 8/21/06, J. Merrill <jvm_cop at spamcop.net<mailto:jvm_cop at spamcop.net>> wrote:
You can get the line number info by using Dino's code (calling sys.exc_info).  Are you concerned that the default traceback display doesn't show the line number?

At 01:44 PM 8/21/2006, Matt Beckius wrote


No 32bit.  I tried manually setting the TraceBackSupport, but still got the same result:

IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> import IronPython
>>>
>>> IronPython.Compiler.Options.TraceBackSupport = True
>>> def Test():
...     print "test"
...     int("test")
...
>>> Test()
test
Traceback (most recent call last):
  File , line 0, in <stdin>##12
  File , line 0, in Test
ValueError: invalid integer number literal
>>>


On 8/21/06, Dino Viehland < dinov at exchange.microsoft.com<mailto:dinov at exchange.microsoft.com>> wrote:
Are you running on a 64-bit machine w/ a 64-bit runtime?  By default we disable trackback support on 64-bit machines (we've hit a unique bug w/ exception handling there), but it is enabled on 32-bit machines and should work there.

If I do:

import sys
def test2():
    try: test()
    except ValueError, ex:
        global e
        import sys
        e = sys.exc_info()

test2()
e

>>> e[2].tb_lineno
2
>>> e[2].tb_frame.f_code.co_filename
'<stdin>'

You can enable on 64-bit:

import IronPython
IronPython.Compiler.Options.TraceBackSupport = True

From: users-bounces at lists.ironpython.com <mailto:users-bounces at lists.ironpython.com> [ mailto:users-bounces at lists.ironpython.com] On Behalf Of Matt Beckius
Sent: Monday, August 21, 2006 7:18 AM
To: users at lists.ironpython.com<mailto:users at lists.ironpython.com>
Subject: [IronPython] Getting a line number of error (RC2)

Trying to get the line number of an error.  CPython produces:

Python 2.4.2 (#67, Sep 28 2005, 12:41:11)
Type "help", "copyright", "credits" or "li
>>> def test():
...     print "hi"
...     int("hi")
...
>>> test()
hi
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 3, in test
ValueError: invalid literal for int(): hi


But IP RC2 produces:

IronPython 1.0.60816 on .NET 2.0.50727.42
Copyright (c) Microsoft Corporation. All rights reserved.
>>> def test():
...     print "hi"
...     int("hi")
...
>>> test()
hi
Traceback (most recent call last):
  File , line 0, in <stdin>##5
  File , line 0, in test
ValueError: invalid integer number literal

How do I get the line number of this runtime error?

MattB


J. Merrill / Analytical Software Corp

_______________________________________________
users mailing list
users at lists.ironpython.com<mailto:users at lists.ironpython.com>
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/ironpython-users/attachments/20060822/8a7bc36e/attachment.html>


More information about the Ironpython-users mailing list