Checked vs Unchecked Exceptions in Java

Checked exceptions must be declared or caught at compile time; unchecked exceptions (RuntimeException) don't require handling. Learn when to use each.

Published September 22, 2026

A checked exception (any subclass of Exception other than RuntimeException) must be either caught or declared with 'throws' in a method's signature, enforced at compile time. An unchecked exception (subclasses of RuntimeException) has no such requirement — the compiler doesn't force calling code to handle it.

Common causes

  • Java's designers wanted to force explicit handling of recoverable conditions the caller should reasonably anticipate (like a missing file), while leaving programming errors (like a null pointer or invalid array index) unchecked since they typically indicate a bug rather than an expected condition

How to fix it

  • Use checked exceptions for conditions a well-written caller could reasonably recover from, like IOException when a file might not exist
  • Use unchecked exceptions (extending RuntimeException) for programming errors or invariant violations that shouldn't normally be caught and handled, only fixed in code
  • Avoid creating new checked exceptions for every possible failure — overuse leads to try/catch boilerplate that often just rethrows or swallows the exception without adding value

Example

// Checked — caller must handle or declare
public void readFile() throws IOException { ... }

// Unchecked — no such requirement
public void divide(int a, int b) {
    if (b == 0) throw new IllegalArgumentException("b cannot be 0");
}

FAQ

Is RuntimeException checked or unchecked?

Unchecked — RuntimeException and all of its subclasses (NullPointerException, IllegalArgumentException, etc.) are unchecked and don't need to be declared or caught.

More Java articles