I am running a middle sized django project, whenever a error occurs a traceback is printed, but many functions where Django modules.
But the actual culprit in my own project code, it has only one line, and useful context were hidden because of the traceback depth limit. So I am thinking of filter the call stack by module path instead of call depth.
In case you haven't seen this problem, I have an very similar example in Java. What I need is to make sure the business logic code shows upfront in an exception.
While I am aware of traceback.print_exc()
, but you need to wrap every code in a try ... except
.
Is it possible to change python's default traceback behavior so django's call stack is fewer and my own code is larger portion?
Whenever an unhandled exception arises, this is the function that Python calls to do the printing
sys.excepthook(type, value, traceback)
type: the exception class
value: the exception instance that wasn't handled
traceback: a trackeback object; the same as what is stored in sys.last_traceback
Read more
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With