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

Alternative to raise

Instead of raise, could we have used just an if .... else.... ? Also, the error "err" will always be printed? Even if the number of people is above 1?

Thanks

1 Answer

An if-else block will do no good, because how do you know what to put inside? Are you going to print the error message? Imagine that you have a smart audio device and invoke that method by saying out loud "Split a check of 20 dollars by 0 people", how can it print the error message if the only input/output is an audio interface? In this case, the smart audio device might choose to verbalise the error message text via the speakers, but a light bulb might choose to switch its color to red. You throw/raise the exception, and then it's up to the caller to handle it appropriately.

I see, that makes sens. Thank you!