Compile time vs runtime error

Compile time vs runtime error #

Definition. In (pre)compiled languages (like Java, C/C++, C#, Haskell, Python, Go, Rust, etc.):

  • A compile time error prevents a program from compiling. It can be thought of as a “syntactic” error.
  • A runtime error (also called a bug) occurs during the execution of a program. It may depend on the input of the program.

Note. An IDE can identify some compile time errors (and highlight them), without even attempting to compile the program.

In practice #

  • Compile time errors tend to be (much) easier to fix than bugs, especially in large projects.
  • Some bugs are only detected after a program is released, which may have a cost.

Expressive type constraints can help identifying errors at compile time.

In interpreted languages #

For interpreted languages (like Javascript, Lua, etc.), the term “compile time error” is meaningless (since these are not compiled).

However, a distinction can still be made between errors that can be preemptively identified (e.g. highlighted by an IDE), and errors that can only be detected at runtime.