How to print the stack trace when an exception is encountered in Python

Printing the stack trace when an exception is encountered prints the full error message of a traceback error.

Solution for How to print the stack trace when an exception is encountered in Python : You can use traceback.print_exc() to print the stack trace when an exception is encountered Create a try and except block. In the except block, call traceback.print_exc() to print the stack trace of the exception.


how-to-print-the-stack-trace-when-an-exception-is-encountered-in-python