When creating some basic programs in Python, I occasionally run into errors that bring the word traceback , so I was curious to find out what traceback meant.
When creating some basic programs in Python, I occasionally run into errors that bring the word traceback , so I was curious to find out what traceback meant.
It is the same as stacktrace , a term a little more used in languages in general. The literal translation is tracking. So it's to track what the application is doing, but in a simple way.
The code is always executed in a function call stack, ie every function that is called is placed on that stack.
When the runtime error encounters the stack to find all the functions that were called, the line number that each function is running at that time, if the information is available (except the first , always shows a line where the next function call is being called), and eventually some other information such as the file name, module, or something.The stack is usually shown in the stacked order, so the last one (it's on top of the stack) shows first. Ma in Python shows in the order of call.
Obviously the error generated shows what caused it, which is one of the most important information.
def a():
i = 0
j = b(i)
return j
def b(z):
k = 5
if z == 0:
c()
return k / z
def c():
error()
a()
Generate traceback :
Traceback (most recent call last): File "tb.py", line 15, in <module> a() File "tb.py", line 3, in a j=b(i) File "tb.py", line 9, in b c() File "tb.py", line 13, in c error() NameError: global name 'error' is not defined
It is important to know what went wrong and know where to look to fix the error. You need to learn how to interpret this information to be able to debug the application.
The quality of the information depends on the runtime of the language.
The only way to avoid this is to not let the application generate an error. Too bad some people understand that for this it is better to catch all the bugs before the application breaks down and show the traceback . When the error is programming, it is critical. It may even make it not appear to the user, but this information can not be missed, it needs to be shown to the programmer somewhere. Programming error only solves fixing the problem.
It is possible to make a more detailed trace operation that is possible, it does not have a generated error, it serves the same purpose, but it is a very different mechanism, starting with being on demand .