Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (50.2k points)

I want to print the exact same result that is displayed when the exception is raised without the try..except intercepting the exception, and I do not want it to exit my program. How do I do this?

try:

    do_stuff()

except Exception, err:

    print(Exception, err)

    # I want to print the entire traceback here,

    # not just the exception name and details

1 Answer

0 votes
by (108k points)

Kindly be informed that the traceback.format_exc() or sys.exc_info() in python will produce more info if that's what you desire.

import traceback

import sys

try:

    do_stuff()

except Exception:

    print(traceback.format_exc())

    # or

    print(sys.exc_info()[2])

Browse Categories

...