π The Simple Version
What is a stack trace?
A stack trace is like a breadcrumb trail left by your program when it crashes. It shows the series of function calls that led to the error.
Key parts to look at
- File and line number β where the error happened.
- Function name β which function was running.
- Error message β what went wrong.
How to follow the trail
1. Start at the top line β thatβs where the crash began. 2. Read the file and line number, open the file, and jump to that line. 3. If it calls another function, look at that function next in the trace. 4. Keep going until you reach the original source of the bug.
Traceback (most recent call last):
File "main.py", line 42, in <module>
main()
File "main.py", line 30, in main
result = calculate()
File "calc.py", line 18, in calculate
return 10 / 0
ZeroDivisionError: division by zero
Quick tips & analogies
- Think of a stack trace like a waiter calling you back: the top line is the waiter, the next lines are the dishes you ordered, and the bottom line is the kitchen.
- Donβt panic β the error message is a hint, not a verdict.
- Use a debugger to step through the code if the trace is confusing.