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

Different solution of error handling

Hello, I solve error problem in different way then Craig. I raise exception as err, not like in the lesson ValueError twice. Is it correct? Regards Dawid

try: ticket_ammount = int(input("Hello {}, how many tickets do You want?: ".format(name))) if ticket_ammount > tickets_remaining: raise Exception("Sorry! We have only {} tickets".format(tickets_remaining)) except Exception as err: print(err) except ValueError: print("{}, You must type a number!!!".format(name))

1 Answer

Steven Parker
Steven Parker
229,732 Points

When you have a generic exception handler, it should be the last one in the series. Otherwise, the specialized handlers (like the one here for ValueError) will never get a chance to run since the generic one will handle them also.

As long as you observe that rule, using a generic handler is OK.

Thank You!