I am looking for the equivalent of PHPs InvalidArgumentException to use in case a function gets an argument that has an incorrect type. I'm working with Python 3. (And I am quite new to Python.)
ValueError documentation states "argument that has the right type but an inappropriate value", so is not the right one to use here.
TypeError documentation states "Raised when an operation or function is applied to an object of inappropriate type", and thus also does not seem applicable.
What is the correct error type to use in my case?
I would go with TypeError in your case.
A function is applied to an object of inappropriate type can be understood as passing an argument of the wrong type (the function is applied to its arguments).
For instance, len(42) raises TypeError, because len() cannot be applied to a number.
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