Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
What does ValueError mean?
Except is a block, what is ValueError? a variable?
try: count = int(input('give me a number: ')) except ValueError: print("That's not a number")
if I change ValueError to valueerror or Valueerror or any other word, it will get error as below:
give me a number: f Traceback (most recent call last): File "exception.py", line 2, in <module> count = int(input('give me a number: ')) ValueError: invalid literal for int() with base 10: 'f' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "exception.py", line 3, in <module> except Valueerror: NameError: name 'Valueerror' is not defined
Thank you in advance.
Steven Parker228,025 Points
ValueError is a type of exception.
It's the specific type of exception that would occur if the int operation on the previous line fails, so it's what you want your code to react to when it happens.
Just like variable names, exception names are case sensitive (as you discovered).