DEV Community

Cover image for "A beginner-friendly breakdown of the two errors every developer faces"
Arul .A
Arul .A

Posted on

"A beginner-friendly breakdown of the two errors every developer faces"

What is a Compile-Time Exception?
A compile-time exception (also called a checked exception or compile-time error) is an error that is detected by the compiler before the program even runs. The compiler reads your source code, checks it for mistakes, and refuses to build the program if it finds problems.Think of it like a spell-checker in Microsoft Word — it catches errors before you print the document.

Common causes:

  • Syntax errors (missing semicolons, brackets)
  • Type mismatches (assigning a string to an integer variable)
  • Calling a method that doesn't exist
  • Missing imports or undefined variables

Example in Java:

int x = "hello";  // ERROR: cannot assign String to int

Enter fullscreen mode Exit fullscreen mode

The compiler catches this instantly — the program never even runs.

Key traits:

  • Caught before execution.
  • Easier to fix — the compiler tells you exactly where the problem is.
  • The program cannot run until all compile-time errors are resolved.

What is a Runtime Exception?

A runtime exception is an error that occurs while the program is actually running. The code compiled successfully and looked fine to the compiler, but something unexpected happened during execution — like dividing by zero or accessing a list index that doesn't exist.
Think of it like a GPS giving you directions — the route looked fine on the map, but mid-journey you hit a road that's closed.

Common causes:

  • Dividing by zero
  • Accessing a null object (NullPointerException)
  • Index out of bounds (accessing list[10] when the list only has 5 items)
  • Invalid type casting
  • File not found

Example in Python:

numbers = [1, 2, 3]
print(numbers[10])  # IndexError: list index out of range
Enter fullscreen mode Exit fullscreen mode

This code looks perfectly fine to Python's interpreter — no syntax issues. But the moment it runs and tries to access index 10, it crashes.

Difference Between CTE And RTE :

Top comments (0)