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
2009-11-09 14:31:27
+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
2009-11-09 14:32:15