Errors vs Exceptions in Java
Throwable is the root of Java's entire exception hierarchy, splitting immediately into two very different branches: Error and Exception. An Error represents a serious problem an application generally shouldn't try to catch or recover from at all — OutOfMemoryError or StackOverflowError signal that the JVM itself is in genuine trouble, and application code catching these rarely helps.
An Exception represents a problem a program can reasonably anticipate and often recover from — a file that doesn't exist, invalid user input, a network request that failed. This three-way split — Error, checked Exception, and unchecked Exception (RuntimeException) — exists specifically to separate "the JVM is in serious trouble" from "something expected went wrong" from "this is very likely a programming bug," and knowing which bucket a problem falls into shapes whether catching it is even the right response.
Throwable is the root
Every single thing that can be thrown in Java, Error and Exception alike, ultimately extends Throwable.
Error
Signals a serious problem, typically with the JVM itself, that application code generally shouldn't try to catch or recover from.
Exception
Signals a problem a program can reasonably anticipate and often meaningfully recover from.
Checked versus unchecked Exception
A further split within Exception, covered in depth in its own topic.
Deciding what to do with a given problem
Depends heavily on which of these categories it actually falls into, not just whether it's technically catchable.
public class ErrorVsExceptionDemo { public static void main(String[] args) { try { int[] numbers = new int[3]; System.out.println(numbers[5]); } catch (ArrayIndexOutOfBoundsException e) { System.out.println("Caught an Exception: " + e.getMessage()); } }}Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Re-implement each visualized algorithm in Java yourself — building beats watching.