Change python defaultbackback behavior to add more code from project path?

I run a medium-sized django project, whenever an error occurs, a trace is printed, but there are many functions where the Django modules are.

But the actual culprit in my own project code, it has only one line, and the useful context was hidden due to the limited trace depth. So I'm thinking of filtering the call stack along the module path instead of the call depth.

If you have not seen this problem, I have a very similar example in Java . I need the business logic code to display in advance in the exception.

So far I know traceback.print_exc(), but you need to wrap each code in try ... except.

Is it possible to change the default trace behavior of python by default so that the django call stack is smaller and my own code is most?

+4
source share
1 answer

Whenever an unhandled exception occurs, this is a function that Python calls to print.

sys.excepthook(type, value, traceback)

type: exception class

value: exception instance that was not handled

traceback: trackeback object; same as sys.last_traceback

More details

+4
source

Source: https://habr.com/ru/post/1619288/


All Articles