I use this code to catch an exception and print a stack trace:
def logerr(stmt, e):
try:
do_something()
except:
print('##EXCEPTION in logging: ')
exc_type, exc_value, exc_traceback = sys.exc_info()
traceback.print_exception(exc_type, exc_value, exc_traceback, file=sys.stdout)
I get a result like:
##EXCEPTION in logging:
Traceback (most recent call last):
File "C:\Users\amurty\Desktop\dev\eclipse\workspace\hhs\FeedSearch\src\main\main.py", line 18, in main
log()
TypeError: log() takes exactly 1 argument (0 given)
But I want the stack trace to have extra indentation, like so:
##EXCEPTION in logging:
Traceback (most recent call last):
File "C:\Users\amurty\Desktop\dev\eclipse\workspace\hhs\FeedSearch\src\main\main.py", line 18, in main
log()
TypeError: log() takes exactly 1 argument (0 given)
How can I achieve this? Will the pprint or textwrap modules help here ?
try this: