Skip to content

Instantly share code, notes, and snippets.

@ShmuelMofrad
Last active December 3, 2017 16:40
Show Gist options
  • Save ShmuelMofrad/97297eab2278ff53497cc892924bb90e to your computer and use it in GitHub Desktop.
Save ShmuelMofrad/97297eab2278ff53497cc892924bb90e to your computer and use it in GitHub Desktop.
IllegalStateException
public class IllegalStateExceptionInWhile {
public static void main(String[] args) {
seeMore();
run();
iamNotWorking();
}
static void run() {
int counter = 0;
while (true) {
counter++;
System.out.println("counter: " + counter);
if (counter >= 8) {
throw new IllegalStateException("it is inappropriate time!");
}
}
}
private static void iamNotWorking() {
System.out.println("I'm not working");
}
private static void seeMore() {
System.out.println("\n`public class IllegalStateException`\r\n" + "`extends RuntimeException`\n"
+ "Signals that a method has been invoked at an illegal"
+ " or inappropriate time. In other words, the Java environment or Java application"
+ " is not in an appropriate state for the requested operation.");
System.out.println("\n\n[ Read more ]\n[ https://docs.oracle.com/javase"
+ "/8/docs/api/java/lang/IllegalStateException.html ]\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment