This appeared in a discussion with a colleague today.
Javadocs for Java IllegalStateException state that it:
Signals that the method was called at an illegal or inappropriate time. In other words, the Java environment or Java application is not in the appropriate state for the requested operation.
And effective Java says (Paragraph 60, page 248):
Another commonly used exception is IllegalStateException. This is usually an exception for a throw if the call is illegal due to the state of the receiving entity. For example, this would be a throw exception if the caller tried to use an object before it was correctly initialized.
There seems to be a bit of a discrepancy. In the second sentence, javadocs sounds like an exception can describe a very broad condition for the state of execution of Java, but the description in Effective Java makes it look like conditions related specifically to the state of the state of the object, the method was called.
Devices that I saw in the JDK (like collections, Matcher ) and in Guava definitely seem to fall into the category Effective Java talks about ("This object is in a state where this method cannot be called"). It is also similar to IllegalStateException sibling IllegalArgumentException .
Are there legal IllegalStateException services in the JDK that refer to the "Java environment" or the "Java application"? Or do any best practice recommendations promote its use for a wider state of execution? If not, then why are these the so-called javadocs ?;)
java exception illegalstateexception
Andrew McNamee Oct 02 2018-12-12T00: 00Z
source share