title: What error to raise when class state is invalid?
body: <p>In a Python class, what type of error should I raise from an instance method when some of the other attributes of the class must be changed before running that method?</p>
  
  <p>I'm coming from a C# background where I would use <code>InvalidOperationException</code>, "the exception that is thrown when a method call is invalid for the object's current state", but I couldn't find an equivalent <a href="http://docs.python.org/library/exceptions.html">built-in exception in Python</a>.</p>
  
  <p>I've been raising <code>ValueError</code> ("raised when a built-in operation or function receives an argument that has the right type but an inappropriate value") when the problem is with the function parameters.  I suppose this is technically an invalid value for the <code>self</code> parameter; is that the right way to treat it?  For example, is this idiomatic: <code>raise ValueError("self.foo must be set before running self.bar()")</code>?</p>