[IronPython] Traceback Objects?

Dino Viehland dinov at exchange.microsoft.com
Tue Sep 5 18:35:03 CEST 2006

This looks to be a bug (note if you're running on a 64-bit box though we disable tracebacks by default due to another issue).  But what appears to be happening is we don't create the traceback if the exception is caught within the method that raises it.  Compare with:

>>> def test():
...     try:
...         test1()
...     except Exception, oErr: print sys.exc_info()
>>> def test1(): raise Exception()
>>> test()
(<class exceptions.Exception at 0x000000000000002B>, <exceptions.Exception instance at 0x000000000000002E>, <traceback object at 0x000000000000002F>)

Where we do create the traceback object.  I've created CodePlex bug 2912 (http://www.codeplex.com/WorkItem/View.aspx?ProjectName=IronPython&WorkItemId=2912) to track this.  Thanks for the report, we'll get this fixed in a post-1.0 release.

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Gary Stephenson
Sent: Tuesday, September 05, 2006 2:56 AM
To: Discussion of IronPython
Subject: Re: [IronPython] Traceback Objects?

Thanks for that, Mark.

For some reason I was unable to find the message from Dino that you quoted.
As for the CPython thing, I'm trying to stick to a policy of only using ipy and C# (and as little C# as possible).



----- Original Message -----
From: "Mark Rees" <mark.john.rees at gmail.com>
To: "Discussion of IronPython" <users at lists.ironpython.com>
Sent: Tuesday, September 05, 2006 6:24 PM
Subject: Re: [IronPython] Traceback Objects?

Was hoping someone with more knowledge would answer your question but think theres been a holiday in the US. I cannot say if IP behaves the same as CPython in this case, but I was going to say that using the the standard traceback module allows printing of the stack. Even one of the IP team said it in a email:
>From: Dino Viehland
>Sent: Wednesday, July 12, 2006 11:54 AM
>To: Discussion of IronPython
>Subject: Re: [IronPython] Getting a call stack from an exception?
>Tracebacks are the correct way to do this, I recommend you install
the standard Python library against IronPython to make this really useful - then you can do import traceback and use its handy functions (otherwise you'll be walking the traceback list in sys.exc_info() which won't be much fun).

But running this code:

import sys, traceback
def test():
    raise Exception()
    print traceback.format_exc()
    print traceback.print_stack()


I got this:

'NoneType' object has no attribute 'tb_frame'
   at IronPython.Runtime.Types.DynamicType.GetAttr(ICallerContext context, Objec t self, SymbolId name)
   at IronPython.Runtime.Operations.Ops.GetAttr(ICallerContext context, Object o , SymbolId name)
   at traceback.print_stack$f14(Object f, Object limit, Object file) in E:\Pytho n24\Lib\traceback.py:line 246
   at IronPython.Runtime.Calls.Function3.Call(ICallerContext context)
   at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext
Object func)
   at test$f159##120(ModuleScope )
   at IronPython.Runtime.Calls.CallTarget0.Invoke()
   at IronPython.Runtime.Calls.Function0.Call(ICallerContext context)
   at IronPython.Runtime.Operations.Ops.CallWithContext(ICallerContext
Object func)
   at <stdin>##121(ModuleScope )
   at IronPython.Hosting.CompiledCodeDelegate.Invoke(ModuleScope
   at IronPython.Hosting.CompiledCode.Run(ModuleScope moduleScope)
   at IronPython.Hosting.PythonEngine.ExecuteToConsole(String text, EngineModule  engineModule, IDictionary`2 locals)
   at IronPython.Hosting.PythonEngine.ExecuteToConsole(String text)
   at IronPythonConsole.PythonCommandLine.DoOneInteractive()
   at IronPythonConsole.PythonCommandLine.<RunInteractiveLoop>b__6(Boolean&
 interactiveAction, Boolean& continueInteraction)
AttributeError: 'NoneType' object has no attribute 'tb_frame'

So maybe it is a bug, or you can use traceback for simple things but not printing the stack or maybe it only affects Australians like you and me.


On 9/5/06, Gary Stephenson <garys at ihug.com.au> wrote:
> My third attempt at asking this question (as the previous two went
> through to the 'keeper) ...
> Is the following considered a bug in IronPython, or am I doing
> something wrong?
>  import sys
>  def test():
>    try:
>        raise Exception()
>    except Exception, oErr:
>        print sys.exc_info()[2]       # None in ipy, traceback object in
> CPython
>        print sys.exc_traceback    #  ditto..
>  test()
> Regardless of the answer to the previous question, a printout of a
> stack trace does currently occur on an unhandled exception.  Other
> than redirecting stderr (which I _assume_ would work), is there an
> easy way of logging the traceback message to a file?
> Apologies if I am asking unwelcome nooby questions.  Should I perhaps
> be asking on another forum, and if so, which?
> thanks in advance,
> gary
> _______________________________________________
> 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

users mailing list
users at lists.ironpython.com

More information about the Ironpython-users mailing list