views:

383

answers:

3

I have a traceback object that I want to show in the nice format I get when calling traceback.format_exc() Is there a builtin function for that, or a few lines of code?

+4  A: 

format_exc is really just

    etype, value, tb = sys.exc_info()
    return ''.join(format_exception(etype, value, tb, limit))

So if you have the exception type, value, and traceback ready, it should be easy. If you have just the exception, notice that format_exception is essentially.

    list = ['Traceback (most recent call last):\n']
    list = list + format_tb(tb, limit)

where limit defaults to None.

Martin v. Löwis
+3  A: 

Have you tried traceback.print_tb or traceback.format_tb?

Nadia Alramli
+2  A: 

traceback docs give few examples and whole set of functions for formatting traceback objects.

SilentGhost