What is the difference between a compiler error, a runtime error and a logic error?
They differ in when the problem is discovered, and that ordering is also the order of increasing cost.
Compile-time errors are found before the program runs. Syntax errors, type mismatches, undefined variables, missing imports, calling a function with the wrong number of arguments.
These are the cheapest possible errors. The compiler tells you the file, the line and usually what is wrong, and the program cannot run until it is fixed — so it can never reach a user.
Runtime errors occur during execution. Null or undefined dereferences, division by zero, array index out of bounds, file not found, network timeout, out of memory, failed type conversion.
These are more expensive because they depend on inputs and conditions. Code containing one may run correctly thousands of times and fail on a particular input, and finding it requires reproducing the circumstances. Many runtime errors are not bugs at all — a network failing is an expected condition that must be handled, not prevented.
Logic errors are the most expensive. The program compiles, runs without error, and produces the wrong answer. The computer did exactly what you told it; what you told it was wrong.
Examples: an off-by-one in a loop boundary, inverted comparison, wrong operator precedence, incorrect formula, or a condition that is right for the common case and wrong at the edges.
Nothing reports them. They surface through tests, through review, or through a user noticing an incorrect figure — sometimes long after deployment, by which point wrong data may have accumulated.
The practical implication is to push errors earlier:
Static typing converts a large class of runtime errors into compile-time errors — the core argument for TypeScript, Rust and similar.
Linting and static analysis catch more before running.
Tests are the main defence against logic errors, since nothing else detects them.
Assertions and validation at boundaries fail fast rather than corrupting state silently.