Reading an Error Message
Beginners see a red error and feel stopped. Experienced programmers see the same error and feel informed, because an error message is the most precise documentation you will ever get about your own code.
Every error tells you three things: what kind of problem it was, where it happened, and what the program was trying to do.
The errors you will meet most:
SyntaxError, the code is not valid language at all, usually a missing bracket, quote, or colon.
NameError (Python) / ReferenceError (JS), you used a name that does not exist. Often a typo.
TypeError, you did something to a value its type does not support, like adding a number to a list.
IndexError (Python), you asked for a position that does not exist.
KeyError (Python), you asked for a dictionary key that is not there.
ZeroDivisionError, you divided by zero.
✦ How to read a traceback
Read a Python traceback from the BOTTOM up. The last line names the error type and message, and the line just above it shows the exact line of your code that caused it. Everything higher is the chain of calls that got there.
Mark this lesson complete
Signed in, your progress follows you to every device.