Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python Python Basics All Together Now Handle Exceptions

Movrard Herard
PLUS
Movrard Herard
Courses Plus Student 543 Points

https://w.trhou.se/nts7fi3e6k Oh no something went wrong.invalid literal for int() with base 10: 'blue'.

I cant understand where i went wrong. It may be my first imposter syndrome moment.

3 Answers

Ray Karyshyn
Ray Karyshyn
13,443 Points

I'm unsure where you think you went wrong. When you enter 'blue' in for the amount of tickets needed, the try block catches a ValueError and runs the except block. You should get an error.

try:
    tickets_wanted = int(tickets_wanted)  # passing 'blue' returns a ValueError
except ValueError as err:
    # inserts python's error message into your custom message
    print("Oh no something went wrong. {}. Please try again".format(err))
Movrard Herard
PLUS
Movrard Herard
Courses Plus Student 543 Points

Thanks for the answer and sorry for my late reply. Im assuming i didnt save before attempting to run it again. Thanks again

Kyle Lewis
Kyle Lewis
463 Points

I ran into this problem as well. The problem arises because we have two different exceptions being raised as the same ValueError. In the exception block, the line 'print("({})".format(err))' is giving you the grief. It is made to spit out the exception text that was thrown and it dose not discriminate on which exception it was. Its good for when we raised the custom exception about not having enough tickets remaining. But when you try to use anything but an integer when inputting amount of tickets to buy, it also will spit out the exception you are now witnessing. In order to fix this issue, I had to make a custom exception named InvalitTicketsRemaining and add and extra exception block.