getting tracebacks from traceback objects

Discussion in 'Python' started by Michael P. Soulier, Jun 24, 2005.

  1. Hello,

    For a GUI app I've tried resetting sys.excepthook to my own
    exceptionhandler bound method, which accepts a type, value and traceback
    object.

    Now, the traceback module has print_exc and format_exc methods that are
    supposed to take a traceback object and return a formatted traceback
    like the default output. Unfortunately I keep getting 'None' out of
    them. Not sure why.

    Happens here too.

    >>> def handler(type, value, tb):

    ... traceback.print_exc(tb)
    ...
    >>> import traceback
    >>> import sys
    >>> sys.excepthook = handler
    >>> assert(False)

    None

    Pretty sure this worked in 1.5.2. Am I doing something wrong here?

    I want format_exe especially, since I don't want to print to stdout, I
    want to provide the traceback in a popup dialog.

    Thanks,
    Mike

    --
    Michael P. Soulier <>
    http://www.digitaltorque.ca
    http://opag.ca python -c 'import this'
    Jabber:

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.0.7 (GNU/Linux)

    iD8DBQFCu026KGqCc1vIvggRAusVAJ9dhQtIRM3RFABDNTXbe8ol5NP2TQCgmItT
    cavao1soJ0Nrkw23q4nbMys=
    =H7vZ
    -----END PGP SIGNATURE-----
    Michael P. Soulier, Jun 24, 2005
    #1
    1. Advertising

  2. Michael P. Soulier

    Kent Johnson Guest

    Michael P. Soulier wrote:
    > Hello,
    >
    > For a GUI app I've tried resetting sys.excepthook to my own
    > exceptionhandler bound method, which accepts a type, value and traceback
    > object.
    >
    > Now, the traceback module has print_exc and format_exc methods that are
    > supposed to take a traceback object and return a formatted traceback
    > like the default output. Unfortunately I keep getting 'None' out of
    > them. Not sure why.


    You are misreading the docs. print_exc() and format_exc() take args of [limit[, file]] not a traceback.

    > I want format_exe especially, since I don't want to print to stdout, I
    > want to provide the traceback in a popup dialog.


    Use format_exception() or pass a StringIO object as the file parameter to print_exc().

    Kent
    Kent Johnson, Jun 24, 2005
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?ISO-8859-1?Q?Mike_M=FCller?=

    tracebacks in embedded python

    =?ISO-8859-1?Q?Mike_M=FCller?=, Jul 9, 2003, in forum: Python
    Replies:
    1
    Views:
    320
    Thomas Heller
    Jul 9, 2003
  2. Maxwell Hammer

    Help with thread related tracebacks

    Maxwell Hammer, Jun 16, 2005, in forum: Python
    Replies:
    0
    Views:
    295
    Maxwell Hammer
    Jun 16, 2005
  3. Maxwell Hammer
    Replies:
    7
    Views:
    631
    Peter Hansen
    Jun 18, 2005
  4. Roy Smith

    Getting terse tracebacks?

    Roy Smith, Jan 1, 2006, in forum: Python
    Replies:
    1
    Views:
    253
  5. Jack Bates
    Replies:
    0
    Views:
    265
    Jack Bates
    May 2, 2011
Loading...

Share This Page