Syntax Error vs Runtime Error
A syntax error stops the code before a single line runs. A runtime error waits until the code hits a bad value.
Syntax Error
Code that breaks the grammar rules of its language. Not one line of it runs.
A syntax error is code that breaks the grammar rules of its language. A missing bracket, a stray comma or a misspelled keyword are common causes. The computer cannot even read the program, so not one line runs. The message points to the line where it got confused. The real mistake is often on that line or the one just above it.
Runtime Error
An error that shows up while the program runs. Some input sets it off.
A runtime error happens while the program is running. The code is written right, so it starts. Then it hits something it cannot do. Dividing by zero, opening a file that is not there and using a null value are common causes. The program stops at that line and shows a message. Often it only happens with certain input, so it can hide for a long time.
In one line
- Syntax Error
- Code that breaks the grammar rules of its language. Not one line of it runs.
- Runtime Error
- An error that shows up while the program runs. Some input sets it off.