RuntimeException
Java Programming Language
Severity: ModerateWhat Does This Error Mean?
RuntimeException is the parent class for all unchecked exceptions in Java — the kind that do not need to be declared or caught. You will rarely see 'RuntimeException' itself; usually you see a specific subclass like NullPointerException, ArrayIndexOutOfBoundsException, or ClassCastException. If you see RuntimeException directly, it means either a library is throwing it as a generic error, or code is using 'throw new RuntimeException(message)' as a quick way to signal a failure.
Affected Models
- Java 1.0 and later
- Java SE
- Java EE
- Android
Common Causes
- A library or framework wraps another exception in RuntimeException and re-throws it
- Code uses 'throw new RuntimeException(e)' to convert a checked exception into an unchecked one
- A method encountered an unexpected state and threw a generic RuntimeException with a custom message
- Spring or other frameworks often wrap exceptions in RuntimeException subclasses
- A specific subclass like NullPointerException, IllegalArgumentException, or ClassCastException is the real cause — check the stack trace
How to Fix It
-
Read the full stack trace carefully. Look for a 'Caused by:' section — this shows the original exception that was wrapped inside the RuntimeException.
In Java, exceptions can be chained. The outer RuntimeException is the wrapper; the 'Caused by' exception is the actual problem.
-
If a specific subclass is shown (like NullPointerException), focus on fixing that specific issue. The RuntimeException is just the wrapper.
Search the specific exception name for more targeted help — NullPointerException, ClassCastException, and similar errors each have their own fixes.
-
If the RuntimeException has a message (like 'User not found' or 'Invalid configuration'), read the message — it is the developer's description of what went wrong.
Exception messages are written for developers. They often tell you exactly what value was wrong or what condition was violated.
-
Do NOT catch RuntimeException blindly with a broad catch block to suppress it. Fix the underlying problem instead.
catch (RuntimeException e) { /* ignore */ } is extremely dangerous — it hides real bugs. Only catch exceptions you can actually handle.
-
If you are writing code and need to signal an error condition, throw a specific subclass like IllegalArgumentException or IllegalStateException instead of plain RuntimeException.
Specific exception types give more information to the caller. 'throw new IllegalArgumentException("userId must not be null")' is much clearer than 'throw new RuntimeException("error")'.
When to Call a Professional
RuntimeException is almost always fixable yourself. Read the full stack trace — the 'Caused by' section shows the original exception if one was wrapped. The real error is usually a more specific exception listed below the initial RuntimeException.
Frequently Asked Questions
What is the difference between checked and unchecked exceptions in Java?
Checked exceptions (like IOException) must be either caught or declared with 'throws' in the method signature. The compiler enforces this. Unchecked exceptions (RuntimeException and its subclasses) do not need to be declared or caught. The compiler does not require it. The philosophy: checked exceptions are for expected failure conditions (like file not found). Unchecked are for programming errors (like null pointer).
Why do developers wrap exceptions in RuntimeException?
Sometimes code needs to call a method that throws a checked exception, but the calling context cannot or should not handle it — like inside a lambda or a Runnable. Wrapping in RuntimeException converts the checked exception to unchecked so it can propagate without being declared. Example: try { doSomething(); } catch (IOException e) { throw new RuntimeException(e); } The original exception is preserved as the 'cause' and is visible in the stack trace.
What is the RuntimeException hierarchy?
RuntimeException is the parent of all unchecked exceptions. Common subclasses include: NullPointerException, ArrayIndexOutOfBoundsException, ClassCastException, IllegalArgumentException, IllegalStateException, ArithmeticException, NumberFormatException, and many others. All of these are RuntimeExceptions — catching RuntimeException catches all of them at once.