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

1

6

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?

Criticaster answered 10/12, 2015 at 1:39 Comment(0)
A
3

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

Anecdotal answered 10/12, 2015 at 6:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.