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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Niki Nikiforidi](https://secure.gravatar.com/avatar/cbe8022f83b1ef539d8aeeb1c4ace8bf?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Niki Nikiforidi
449 PointsIf 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?
2 Answers
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsHey Niki Nikiforidi, good question. Here’s the flow when a 0 is entered:
- line 11, zero is entered
- line 12, function
split_check
called with parameters (20, 0) - line 4, function begins running within
total=20, number_of_people=0
- line 5, value of
number_of_people
checked 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
-
try
block lines 10-12, has error. Jump to line 13 - line 13, if error raised is of type
ValueError
, seterr
to 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!!!
![Niki Nikiforidi](https://secure.gravatar.com/avatar/cbe8022f83b1ef539d8aeeb1c4ace8bf?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Niki Nikiforidi
449 PointsThank 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?
![Chris Freeman](https://uploads.teamtreehouse.com/production/profile-photos/1153532/micro_image.jpg)
Chris Freeman
Treehouse Moderator 68,425 PointsYou are correct that the flow changes when an error occurs or is explicitly raised. In this case, the error does get raised until line 6 in the flow shown in the other answer.
The assignment to the module-level defined number_of_people
in line 11 triggers nothing, so flow naturally flows to line 12.
It is only after the local parameter number_of_people
inside of the function split_check
is set to point at the same object as the module-level number_of_people
points to and then this local variable is checked in line 5 that an error is raised.
Until the error is actually raised, flow moves normally.