Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Python by (19k points)

I have a chunk of Python 2.7 code that may raise an exception. I would like to catch it and assign to a string its full description and the stack trace that caused the error (simply all we use to see on the console). I need this string to print it to a text box in the GUI.

Something like this:



except Exception as e: 


The problem is: what is the function complete_exception_description?

1 Answer

0 votes
by (106k points)

To get the exception description and stack trace which caused an exception, all as a string you need to use the traceback module, mainly the format_exc() function. 

import traceback


   raise ValueError

except ValueError:

   tb = traceback.format_exc()


    tb = "No error"



Related questions

Browse Categories