Course contentsShow
← Java
Lesson 775 of 2,87019. Exception Hierarchy and Custom ExceptionsFree lesson

Error vs Exception: Two Branches of Throwable

Learn the fundamental difference between Error (serious system problems) and Exception (recoverable conditions).

Error vs Exception: Two Branches of Throwable

What you'll learn: You'll understand why Java divides Throwable into two distinct branches—Error and Exception—and when each matters.

The Two Families Under Throwable

In the previous lesson, you learned that Throwable is the root class for everything that can be thrown in Java. Now it's time to understand its two direct children: Error and Exception.

These aren't just arbitrary categories—they represent fundamentally different kinds of problems:

Error: Serious System Problems

Error and its subclasses represent severe problems that applications should not try to catch. These are typically issues with the Java Virtual Machine itself or the environment:

  • OutOfMemoryError – The JVM has run out of memory
  • StackOverflowError – Infinite recursion exhausted the call stack
  • VirtualMachineError – The JVM is broken or corrupted

Think of Error as the building catching fire. You don't try to fix it from inside your office—you evacuate. These conditions are beyond your program's control.

Exception: Recoverable Conditions

Exception and its subclasses represent conditions your application can reasonably anticipate and handle:

  • FileNotFoundException – File doesn't exist (you can prompt for another)
  • IOException – Network hiccup (you can retry)
  • IllegalArgumentException – Bad input (you can reject it gracefully)

Think of Exception as a closed door. You can handle it: find another door, wait, or ask for a key.

Why the Distinction Matters

You write catch blocks for Exception types because you can recover. You typically don't catch Error types—there's nothing your code can do about a collapsing JVM.

Key Takeaway: Error represents unrecoverable system failures you shouldn't catch; Exception represents recoverable problems your application should handle with try-catch blocks.