If I were writing a Python function which received an argument with the correct type, but a value out of bounds, then I might throw a ValueError or one of its sub-classes.
For example, suppose I had a function which added up the prices on an invoice. If one of the prices had a negative value or one of the item-counts was not positive and non-zero I might raise VE.
My current project is in Java, but the situation is the same:
A pricing function accepts only numbers within a specific range - what's the most sensible kind of exception object to throw that tells another Java developer their input is out of that sensible range?
The standard library defines IllegalArgumentException
:
throw new IllegalArgumentException();
I would use an IllegalArgumentException
for this purpose.
java.lang.IllegalArgumentException
.
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