Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change python's default traceback behavior include more code from project path?

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?

like image 206
est Avatar asked Dec 10 '15 01:12

est


1 Answers

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

like image 185
fedorshishi Avatar answered Oct 05 '22 20:10

fedorshishi