What is the analog for .Net InvalidOperationException
in Python
?
As a Python developer you can choose to throw an exception if a condition occurs. To throw (or raise) an exception, use the raise keyword.
InvalidOperationException is used in cases when the failure to invoke a method is caused by reasons other than invalid arguments. Typically, it is thrown when the state of an object cannot support the method call. For example, an InvalidOperationException exception is thrown by methods such as: IEnumerator.
There's no direct equivalent. Usually ValueError
or TypeError
suffices, perhaps a RuntimeError
or NotImplementedError
if neither of those fit well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With