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 Python Basics Functions and Looping Raising Exceptions

Shaun Barbour
PLUS
Shaun Barbour
Courses Plus Student 1,907 Points

(raising errors, try, except) vs. checking the validity of the input within the function with if and elif.

for this specific lesson, why wouldn't you just check the validity of the user input within the function with if, elif, and else statements? if input is not valid, give the user a message and call the function again. seems a lot cleaner and easier to understand.

1 Answer

Steven Parker
Steven Parker
231,269 Points

The fact that the chapter name is "Raising Exceptions" is likely to be a clue here. You're probably right that exception handling isn't the simplest way to implement the validity checks, but the validity checks might be a simple way to illustrate how exception handling can be implemented.

As the lessons move into more advanced techniques, you'll probably see more cases where the application they are applied to seem a bit trivial. But the simple examples are good for understanding the concepts. In actual practice you may use these is much more complex situations.