What does Traceback mean?

Asked

Viewed 4,477 times

10

When creating some basic programs in Python, I occasionally come across errors that bring the word traceback, so I was curious to find out what traceback means.

1 answer

8


Is the same as stacktrace, a somewhat more commonly used term in general languages. Literal translation is tracking. So it serves to track what the application is doing, but in a simple way.

The code is always executed on a stack of function calls, meaning each function that is called is placed on that stack.

When an error occurs Runtime of the language searches that stack to find all 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 is being called), and eventually some other information, such as file name, module, or something like that.

The stack is usually shown in stacked order, so what was called last (is on top of the stack) shows first. Ma in Python shows in call order.

Obviously the error generated shows what caused it, which is one of the most important information.

Example from Wikipedia:

 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()

Generates the 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

I put in the Github for future reference.

It is important to know what went wrong and know where to look to fix the mistake. 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 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 capture all the mistakes before the application break and show the traceback. When the error is of programming, it is fundamental. It may make it not appear to the user, but this information cannot be wasted, it needs to be shown to the programmer somewhere. Programming error only solves if fixing the problem.

It is possible to perform an operation of trace more detailed that it is possible to do, regardless of having a generated error, serves the same purpose, but it is a very different mechanism, starting with being on demand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.