When Python hits something it can't do, dividing by zero, opening a file that isn't there, it raises an exception. An exception is Python's way of saying "I can't continue with this", and unless you handle it, the whole script stops on the spot.
Try to open a file that doesn't exist:
open("/etc/missing.conf")
Python prints a traceback and exits:
Traceback (most recent call last):
File "script.py", line 1, in <module>
open("/etc/missing.conf")
FileNotFoundError: [Errno 2] No such file or directory: '/etc/missing.conf'
A traceback is not noise, it's a map. Read it bottom to top:
FileNotFoundError and the file it couldn't find. This tells you
what went wrong.The bottom line is where to look first. FileNotFoundError on a path
tells you the path is wrong or the file is missing, before you read
another word.
Every failure has a type, and the type tells you the category of problem:
FileNotFoundError: the file or directory isn't there.KeyError: a dictionary key doesn't exist.ValueError: a value has the right type but a wrong content, like
int("abc").ZeroDivisionError: you divided by zero.Knowing the type matters, because handling errors well means catching the specific type you expect, which the next node covers.