views:

158

answers:

2

IllegalStateException is often used in Java when a method is invoked on an object in inappropriate state. What would you use instead in Python?

+2  A: 

ValueError sounds appropriate to me:

Raised when a built-in operation or function receives an argument that has the right type but an inappropriate value, and the situation is not described by a more precise exception such as IndexError.

matt b
+2  A: 

In Python, that would be ValueError, or a subclass of it.

For example, trying to .read() a closed file raises "ValueError: I/O operation on closed file".

ddaa