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 trialMark Roudebush
901 PointsA question about 2 of 2 in the Create a Function quiz
## QUESTION: why doesn't the "B" print? I understand that there was no ValueError so C didn't print and because there was a TypeError "D" printed which means the else ("E") did not. I'm not sure why "B" got skipped.
print("A")
try:
result = "test" + 5
print("B")
except ValueError:
print("C")
except TypeError:
print("D")
else:
print("E")
print("F")
3 Answers
Adam N
70,280 PointsNope. The error occurs at
result = "test" + 5
so that's the last line of the try that will be executed.
You can run the code for yourself here https://repl.it/repls/UnwillingSpringgreenBrace
Adam N
70,280 PointsThe try block will exit out on the line where the TypeError occurs.
More formally:
If an error is encountered, a try block code execution is stopped and transferred down to the relevant except block.
Let me know if this helps here
Mark Roudebush
901 PointsThanks adam n , but wouldn't it read the print("B")
before getting to the try block?
sarah glass
217 PointsThis helped me, too! Thanks.
Mark Roudebush
901 PointsMark Roudebush
901 PointsAh, that makes sense now, thank you!