100

Description for java.lang.IllegalStateException from the Java docs:

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.

Is there an equivalent for IllegalStateException in the .NET-Framework?

1 Answer 1

120

System.InvalidOperationException

The exception that is thrown when a method call is invalid for the object's current state.

3
  • I think this is a better name for that type of exception Commented Jun 13, 2012 at 18:59
  • 27
    @user12345613 I don't. Java's IllegalStateException is not limited to objects nor object state. And the class name InvalidOperationException kind of hints that a method is not supported, but it does not hint that this is because of the state. Commented Jul 1, 2014 at 23:24
  • 3
    @MaartenBodewes You are right; the name alone does not lend itself to quick and easy comprehension. I, too, would not have used (let alone known) that this exception was for object state exceptions purely by it's name without this answer (or the docs at microsoft). That is an issue with the framework. However, IllegalStateException is purely for objects and method calls according the java 7 docs located at docs.oracle.com/javase/7/docs/api/java/lang/… and java 8 docs docs.oracle.com/javase/8/docs/api/java/lang/…
    – Batman
    Commented Sep 1, 2015 at 19:34

Not the answer you're looking for? Browse other questions tagged or ask your own question.