traceback
A traceback is the structured sequence of function calls that the Python interpreter prints whenever an exception (error) is raised. It details the path your code took right before crashing, pointing you to the exact file name, line number, and the type of error encountered.
Traceback (most recent call last):
File "example.py", line 5, in <module>
result = divide(10, 0)
File "example.py", line 2, in divide
return a / b
ZeroDivisionError: division by zero
Reading tracebacks is essential for debugging Python code. It lets you pinpoint the origin of the error and see how different functions relate in the call chain, so you can fix issues more quickly.
Related Resources
Tutorial
Understanding the Python Traceback
In this step-by-step tutorial, you'll learn how to read and understand the information you can get from a Python traceback. You'll walk through several examples of tracebacks and see some of the most common tracebacks in Python.
For additional information on related topics, take a look at the following resources:
- Python Exceptions: An Introduction (Tutorial)
- Python's Built-in Exceptions: A Walkthrough With Examples (Tutorial)
- Getting the Most Out of a Python Traceback (Course)
- Introduction to Python Exceptions (Course)
- Raising and Handling Python Exceptions (Course)
- Python Exceptions: An Introduction (Quiz)
- Python's Built-in Exceptions: A Walkthrough With Examples (Quiz)
By Dan Bader • Updated Jan. 14, 2025