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.
If the code is interrupted, how does raise get run
In the video Raising Expectations, at about 3:55 seconds, he inputs the value 0 for How Many People?, and then the error massage we saved in the function we created was displayed. If we never called split_check, how did python know to display that sentence?
Chris FreemanTreehouse Moderator 67,515 Points
Hey Niki Nikiforidi, good question. Here’s the flow when a 0 is entered:
- line 11, zero is entered
- line 12, function
split_checkcalled with parameters (20, 0)
- line 4, function begins running within
- line 5, value of
number_of_peoplechecked if less than or equal to one. check fails
- line 6, ValueError is raised, error object string set to “More than 1 person is required to split the check”, function returns error. Return to line 12
tryblock lines 10-12, has error. Jump to line 13
- line 13, if error raised is of type
errto error object returned, move to line 14
- line 14, print first string
- line 15, print “More than...” error message from raised error that was set in line 6
Post back if you need more help. Good luck!!!
Thank you for your response. I'm confused how from line 11 it then goes to line 12. From the previous lectures we have been taught that once an error occurs, python leave the line it was at and goes straight to line 13. When is line 12 even touched if at line 11 there is an error?