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! While you're at it, check out some resources Treehouse students have shared here.

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

Python

Euenlee Tan
Euenlee Tan
2,165 Points

For the ticketing challenge in Python

For this particular question, the one that involved Trello and there're 100 tickets left etc. If we were to input 1000 tickets as an answer, the system responded with We ran into an issue. There are only 100 tickets left. Please try again. However, if we were to input the number of tickets as blue, the system will respond with We ran into an issue. invalid literal for int() with base 10: 'blue'. Please try again. . That isn't really user friendly is it? Is there a need for me to raise 2 different value errors and use them separately for each condition ie blue and 1000 tickets?

1 Answer

Steven Parker
Steven Parker
229,732 Points

You don't have to test and raise a separate error,, you could check if the exception string contains the standard text and just replace it with your own instead:

    except ValueError as err:
        # check for the "unfriendly" standard message
        if "base 10" in str(err):
            # then do NOT include the standard text in output
            print("Oh no! That's not a valid entry! You must type a number. Do try again...")
        else:
            # Include the error text in the output
            print("Oh no, we ran into an issue. {}. Please try again".format(err))