Results 1 to 6 of 6

Thread: Patch to print traceback of python exceptions

  1. #1
    ckohnert is offline Registered User
    Join Date
    Aug 2005
    Posts
    9

    Patch to print traceback of python exceptions

    Since python exceptions can occur for so many reasons in a complex setup, it's near impossible to track them down without a traceback. This patch simply hooks into the Ice exception catching to do a quick print to stderr before doing things normally.

    I didn't add a config option because I'm not sure what sort of policies there are for choosing them (nor the best way to hook into it via the API). Something like Ice.Trace.UnknownExceptions=1 would be great to have for languages that can do it relatively easily (java and python that I know of).

    (Diff generated against IcePy-2.1.2)
    Attached Files Attached Files

  2. #2
    ckohnert is offline Registered User
    Join Date
    Aug 2005
    Posts
    9
    Ah, looks like those INCREFs aren't actually necessary (and causes a memory leak warning when you quit). Makes it even simpler without them:

    Code:
    if( <config trace option> )
    {
       PyErr_Restore(t, val, tb);
       PyErr_Print();
    }

  3. #3
    ckohnert is offline Registered User
    Join Date
    Aug 2005
    Posts
    9
    Mutter, okay, just got a seg fault that I cannot reproduce, so obviously one or more of the refs are needed (as I originally thought), but it's not obvious which. Ah well, I'll look again when I get some time.

  4. #4
    ckohnert is offline Registered User
    Join Date
    Aug 2005
    Posts
    9
    After looking at the python source, it looks like the proper way to do this is:

    Code:
    if( <print traceback> )
    {
            Py_XINCREF(t);
            Py_XINCREF(val);
            Py_XINCREF(tb);
            PyErr_Restore(t, val, tb);
            PyErr_PrintEx(0);
    }
    The difference is in the last call which tells it not to 'save' the current exception values when printing them, thus allowing the ref counts to clear normally. Been using this for better part of a day now with no trouble.

  5. #5
    mes's Avatar
    mes
    mes is offline ZeroC Staff
    Name: Mark Spruiell
    Organization: ZeroC, Inc.
    Project: Ice Developer
    Join Date
    Feb 2003
    Location
    California
    Posts
    1,445
    Hi Chris,

    The next release will include a solution, but we're doing it a bit differently. If a server raises an unknown or invalid exception, the Ice run time returns Ice.UnknownException (or one of its derived types) to the client. This exception has a member named 'unknown' which can be used to provide additional information. IcePy will format the exception stack trace and include it in the 'unknown' member.

    If you define the property Ice.Warn.Dispatch=1, the Ice run time will display these unknown exceptions automatically (including the 'unknown' member). The stack trace information is also available to the client.

    Take care,
    - Mark

  6. #6
    ckohnert is offline Registered User
    Join Date
    Aug 2005
    Posts
    9
    Quote Originally Posted by mes
    The next release will include a solution, but we're doing it a bit differently.
    That works too. Good stuff! It was/is darn hard to debug this stuff otherwise.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. why is there only have one message print out?
    By ren-wei in forum Help Center
    Replies: 3
    Last Post: 07-01-2010, 01:58 AM
  2. Viewing "Print" Output Statements in Ice.py
    By afcarl in forum Help Center
    Replies: 2
    Last Post: 05-06-2010, 03:10 AM
  3. Replies: 1
    Last Post: 02-05-2009, 06:49 AM
  4. Replies: 1
    Last Post: 08-01-2006, 06:26 AM
  5. C# exceptions
    By wrobbie in forum Help Center
    Replies: 7
    Last Post: 09-25-2005, 07:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •