IllegalStateException is often used in Java when a method is called on an object in an unsatisfactory state. What would you use in Python?
In Python, it will be a ValueError or its subclass.
ValueError
For example, when you try .read() closed file raises "ValueError: I / O operation in a closed file."
.read()
ValueError sounds suitable for me:
Raised when an inline operation or function receives an argument with the correct type but an invalid value, and the situation is not described by a more precise exception, such as IndexError .