In Java, we have checked exceptions and unchecked exceptions. Also, we have runtime exceptions. My question is - Are all runtime exceptions unchecked exceptions and all unchecked exception are runime excepions? Means can these two words be used interchangeably?
Asked
Active
Viewed 625 times
1 Answers
5
All runtime exceptions (e.g. NullPointerException) are unchecked exceptions.
Since errors (e.g. StackOverflowError) are also unchecked exceptions, not all unchecked exceptions are runtime exceptions.
The Java Language Specifications define an unchecked exception: "The unchecked exception classes are the run-time exception classes and the error classes."

emory
- 10,725
- 2
- 30
- 58
-
Both `java.lang.Error` and `java.lang.Exception` are subclasses of `java.lang.Throwable`, `Error` isn't a subclass of `Exception`. – Joshua Taylor Apr 19 '13 at 21:39
-
@tayloj what you say makes sense except the java language spec specifies otherwise. – emory Apr 19 '13 at 21:40
-
emory is correct. I think its just confusing because of the name "error" and not exception. Thanks for clarifying my ages old doubt.. – Popeye Apr 19 '13 at 21:46
-
@emory Good point. `Exception` and `Error` was a bit pedantic; I saw the comment on the question about the possible duplicate (difference between `RuntimeException` and `Exception`) which was more about the particular classes. This question doesn't mention those, and so it's probably about "exceptions" (lower case 'e'), as discussed in the spec. – Joshua Taylor Apr 19 '13 at 21:47