RuntimeException in Java Hierarchy
Fast recall
Quick revision
Core answer
RuntimeException is the unchecked branch under Exception. Java does not require callers to catch its subclasses or declare them with throws. Types such as NullPointerException, IllegalArgumentException, and IllegalStateException often report invalid use or broken invariants, but applications also use unchecked exceptions for translated infrastructure and domain failures; the name does not mean other exceptions occur outside runtime.Whether you understand the checked vs unchecked split and why unchecked exceptions exist — to avoid forcing try-catch around every line for bugs
Reading 'RuntimeException' as 'exceptions that occur at runtime', and broadly catching RuntimeException instead of fixing the underlying bug
Explain that unchecked = the compiler trusts you to fix bugs, while checked = the compiler insists you plan for external failures
Interview-ready guide
Interview answer
RuntimeException is the main unchecked branch under Exception. Its subclasses can propagate without a throws declaration and callers are not forced to catch them. JDK types often describe invalid arguments, state, indexes, or null use.
I do not say every RuntimeException is a programming bug. Spring and many applications use unchecked hierarchies for translated infrastructure or domain failures that are handled at an outer boundary. The important distinction is the lack of catch-or-declare, not when the exception occurs.
RuntimeException in Java Hierarchy
Direct Answer
RuntimeException is the unchecked branch under Exception. Java does not require callers to catch its subclasses or declare them with throws. Types such as NullPointerException, IllegalArgumentException, and IllegalStateException often report invalid use or broken invariants, but applications also use unchecked exceptions for translated infrastructure and domain failures; the name does not mean other exceptions occur outside runtime.
Code Example
public class OrderService {
// No 'throws' needed for unchecked exceptions
public Order createOrder(Long userId, List<String> items) {
if (userId == null)
throw new IllegalArgumentException("userId must not be null");
if (items.isEmpty())
throw new IllegalStateException("order needs at least one item");
return new Order(userId, items);
}
// A checked exception DOES force a throws declaration
public String readNotes(String path) throws java.io.IOException {
return java.nio.file.Files.readString(java.nio.file.Path.of(path));
}
}
IllegalArgumentException/IllegalStateException are unchecked; the caller is free to ignore them because catch-or-declare does not apply.
Common Mistakes & Pitfalls
- Thinking runtime refers to when it occurs: all exceptions are thrown during execution; this name marks an unchecked branch.
- Calling every RuntimeException a coding bug: frameworks and applications also use unchecked domain and translated infrastructure failures.
- Catching every RuntimeException broadly: catch a specific type only when this layer can act.
- Adding
throws RuntimeExceptionas if required: declaring unchecked failures is optional documentation. - Hiding invalid input: validate at the boundary with a meaningful subtype and message.
Check your understanding
Answer these without looking back at the article.
- Should you ever catch RuntimeException?
- What is the difference between IllegalArgumentException and IllegalStateException?
- How do you decide whether to make a custom exception checked or unchecked?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.