DELAPARRA
Index
Color
NL
Category: Error types

ValueError

Explained by Updated

What is ValueError?

ValueError: A value has the right type but an inappropriate or invalid value for the operation being performed. A ValueError in Python means a function received a value of the right type but with an unacceptable value. int("abc") raises it, because "abc" is a string, as expected, but not one that represents a number.

Definition source Coders Lingo, CC BY 4.0

Frequently asked questions about ValueError

How is ValueError used in practice?

PHP has a similar ValueError for built-in functions, and frameworks often use InvalidArgumentException for the same idea in your own code.

What should you keep in mind with ValueError?

Raise this kind of error in your own functions when input makes no sense, such as a negative quantity or an end date before the start date. Failing early with a clear message is far better than continuing with bad data. For user input, validate before calling such functions and show friendly messages, so a ValueError signals a programming mistake rather than a typo in a form.

At a glance

CategoryError types
Explained by
Updated

More Error types terms

All terms starting with V

Skills

Download all skills (zip)

Manuals

Related services

Need any help?

Stuck on one of these in your own project? Tell me what you are working on and I will tell you how I would approach it.