💥 Runtime Error
6th Grade 💻 Coding
A runtime error is a problem that only shows up while the program is running: the code is written correctly, but at some moment it’s asked to do something impossible, and the program stops.
Examples in Python: ZeroDivisionError — trying to divide by zero. NameError — using a name the computer doesn’t know, like a variable that hasn’t been created yet or a misspelled name. IndexError — asking for an item that doesn’t exist in a list, like item number 10 in a list of three.
Errors like these often depend on the input: the program works great with ordinary numbers and crashes when someone types 0 or a word. That’s why it’s important to test edge cases and add checks to your code before risky actions — for example, “if the number you’re dividing by is 0, show a message instead of dividing.”
For example
print(10 / 0)in Python stops the program with aZeroDivisionError.Print("x")with a capital P causes aNameError, because there’s no such name asPrint.- In a list of three names,
names[3]causes anIndexError— because the only indexes are 0, 1 and 2.
📌 Remember: Runtime = the code is fine, but halfway through it’s asked to do the impossible.
Quick quiz
When does a runtime error show up?
Which error does dividing by zero cause in Python?
Why does Print("x") cause an error?