Is there a Java analogue of IllegalStateException in Python?

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

+42
java python exception
Nov 09 '09 at 14:12
source share
2 answers

In Python, it will be a ValueError or its subclass.

For example, when you try .read() closed file raises "ValueError: I / O operation in a closed file."

+31
Nov 09 '09 at 14:32
source share

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 .

+9
Nov 09 '09 at 14:31
source share



All Articles