Python for Absolute Beginners Transcripts
Chapter: Error handling
Lecture: Stepping through errors in the debugger
0:00 I want to do one more thing to just make sure that you're really getting in the feel for how the control flow works when we hit these errors.
0:08 I'm going to set a breakpoint, right up here. And I'm going to hit the debug button. And I'm going to come in here, and we're going to step
0:13 either over or into our code. So let's step over this, over this, we don't care about the log stuff, we don't care about the header stuff.
0:22 And let's go into this load_rolls here, and first I'm going to really quickly break this. Let's see what's going to happen.
0:29 Let's hit this first, step into our code. And this is fine, this is fine, this is fine. We've opened it you can see, opened up to that file.
0:38 A little more info. But this, if we even step into this, and go deep down into, into Python itself and as we try to work through these steps
0:48 what's going to happen, this is going to hit this line and go broken! And now it stops, what is this? No, nothing. Keep going.
0:57 And it's going to start going down through here. And now this one is going to actually match this
1:01 and go in here so, it's not going to be so unexpected. But it says we have this error, which we named je no not surprising and off it goes.
1:10 And then it just exits and so it picked one of those blocks and it went. Put this back. And let's debug it again.
1:18 This time, let's go through, over step over. I'm not going to go until we start playing the game a little. We'll go down and do that.
1:26 It wants my name I guess. And I'm going to go in, and-whoops console. I want to throw seven, now actually I wanted to stop down here.
1:40 So I didn't step and do it correctly so I have to set the breakpoint down here. Which is fine, and get roll, and now my roll is
1:46 now let's say seven correctly. So, I'm going to step over, and it's going to print out the rolls.
1:52 Let's not do the breakpoint there, and right down to here. It asks what our roll is, and it's going to be seven.
1:59 And now we're back here, and it got the word seven numeral. It's gong to convert that successfully I'm going to say it's fine and just going to return
2:06 it's not going to go into the errors but it's good, comes down and it just keeps playing. And off it goes.
2:11 I don't know if I won, but I'm going to find out let's go down a little bit farther to see if I won. I, think I won? Yes I took the round.
2:17 Alright let's go farther. And now let me type in some junk, something broken. So, broken. This is broken. It's fine.
2:28 It says it's not nothing, so everything's good. But we're going to try this, and it's going to first say, I'm going to start going up
2:34 till I find the first except, the first try-except block. It just happens to be right here it could be that main one as well.
2:40 So we're going to come over here and step. Not going to work, so it goes straight here. Handles the error, returns it up here
2:46 and it doesn't go all the way the main but it says alright we dealt with it and what we decided to do is return none for roll one
2:53 when something invalid was done. So that way, we can trigger this bit of code to just make us do it again. So as you're exploring this error handling
3:00 be sure to use the debugger and step over and into and out of your code to explore the flow of the errors as you go through the program.