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.
Cody Stephenson7,771 Points
Why leverage errors at all to handle some of the disallowed inputs instead of just using more if/try/else logic?
What is the purpose of leveraging errors (in this case the ValueError) instead of just specific logic in a try block? Something like
if input <=1 print("message about needing more than one person") if input > 1 print("successful message with calculated value") else print("message about not being a valid input")
Is the purpose as fundamental as trying to avoid actually running through pieces of code?
I can't really explain it other than that's just how they do it.
The real point is to handle exceptions in a way that can guide users with appropriate feedback without bringing the program execution to a grinding halt.
Usually, it helps to do it in a while loop, so you can keep prompting the user until valid input is provided.
Perhaps I can better explain it with an example:
https://teamtreehouse.com/community/all-together-now-the-project (check my beyond-the-challenge code).
And by the way, if you are interested, I can provide you my code for a python program I wrote to explore the "Monty Hall Game " Problem Paradox - it has A LOT of error handling/exceptions.
As seen here:
I hope that helps.
Stay safe and happy coding!