Python for Absolute Beginners Transcripts
Chapter: Error handling
Lecture: Introduction to Python's error handling

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Well I hope you're proud of the little programs that we created are rock paper scissors and tic tac toe and all the other things.
0:08 And they're pretty good but there's something that we've been overlooking so far. And the reason they've been over looking it is
0:13 I've been trying to focus on the core programming concepts. But no program is done until it is handling bad user input
0:21 or other types of situations that it didn't expect. Here we are now rock paper scissors game and we have a new player crash bandit, uh-oh.
0:29 Well it says please enter a number which one would you like? 1 through 7, I said, Cool, we'll take 7. s-e-v-e-n, enter. Boom!
0:38 Our program exploded, it's done. It didn't just report that it couldn't understand seven. It said, We've crashed so badly, we cannot continue.
0:47 I can see the process finished with exec code 1. That might sound good, 0 is good, non-zero is bad. See it says there's a ValueError
0:55 input literal for int, we can't, it's invalid we can't take the word seven, we need the number 7. You know the purpose is to take quote, the num
1:04 the numeral 7 and turn it to literally the integer seven. And it can't take it this way. Maybe you would expect it could, but it can't.
1:11 So that's a problem, what we need to do is say Hey, we saw that you typed in something wrong no worries, we got you, that was invalid
1:19 why don't you try something like one through seven as a numeral. So that's what were going to focus on in this chapter.
1:25 Were going to keep it pretty short and tight. But there are some essential error handling things we have not touched on, at all.
1:32 And it's going to allow us to catch these errors stop them, figure out what went wrong tell the user what the problem was
1:38 and potentially let them keep on going.


Talk Python's Mastodon Michael Kennedy's Mastodon