Compile-Time Error vs Runtime Error — What's the Difference?

A compile-time error is caught by the compiler (or a type checker) before the program ever runs, based on static analysis of the code; a runtime error occurs...

Published October 6, 2026

A compile-time error is found by the compiler before the program runs (syntax or type mistakes); a runtime error happens while the program is running (division by zero, null access, missing file). Compile-time errors stop the build, runtime errors crash or misbehave in use.

The concept

Compiled and type-checked languages catch many mistakes early: undefined variables, wrong types, missing semicolons.

Runtime errors depend on data and environment, so they can appear only for certain inputs. Handle them with validation and try/catch.

When it fails

write code ▶ compile ▶ run
✗ compile-time error (build fails)
✗ runtime error (crash while running)

Practical examples

Compile-time (Java)

int x = "hello";   // error: incompatible types

Runtime (Java)

int[] a = new int[2];
int b = a[5];   // ArrayIndexOutOfBoundsException

TypeScript catches before run

const n: number = 'x'  // error at build time

Handle runtime errors

try { JSON.parse(input) } catch { console.error('invalid JSON') }

Common mistakes

  • Assuming 'it compiles' means 'it works'.
  • Not validating external input.
  • Ignoring warnings that predict runtime errors.

Key takeaways

  • Compile-time = before running, runtime = while running.
  • Types move bugs earlier.
  • Validate input and handle exceptions.

FAQ

What about logic errors?

The program runs but gives wrong results; only tests and review catch them.

Does JavaScript have compile errors?

Syntax errors are caught at parse time; most others appear at runtime.

More General articles