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