Hi, in this video we're going to talk about debugging with error messages. So when we talk about error messages, it's first important to know the few types of errors. So first there's a syntax error, and when we have a syntax error, our program won't even start running.
That means we might have a typo, or we're not typing our function correctly, or misusing the loop. Then there's a class of errors called runtime errors, where the program actually starts running, but crashes when it's running. And then we have logic errors, where the program starts running and doesn't crash, but doesn't do what it's supposed to do.
So when we get error messages, we'll usually get those from a syntax error or a runtime error. Error messages can sometimes be cryptic, but our system tries to make the error messages a little bit nicer, and there's also useful ways to get information out of them. So that's the focus of what we're going to look at in this lesson.
So let's look at this error. So this says Carol crashed into a wall. Error on line 22. Carol crashed into a wall.
Do you have an extra move command? So here we have an error, a line, and a suggestion on what might be a fix. So there's another error called a reference error.
You can see uncaught reference error. Great steps is not defined. This might mean we have a typo.
We'll have a look at this error in more detail. And then unexpected identifier. This means that there's some sort of typo in getting the program to run, maybe with brackets or parentheses.
So what types of information can we get from error messages? First we should ask these questions. Does the error message reference a function? If so, we could check that function. Does the error message reference a line number?
If so, we can check that line number. Does the error message provide some other sort of hint? How can we use that in our debugging process? So let's debug a problem together.
Okay, so let's look at how we can debug this staircase. So if we look at our result world, we're trying to build a staircase that kind of goes all the way up. So if we run this, oh, we get an error.
It says bad input on line 10. So this is a relatively generic error, but it does point to the line that we have an error on. So we can kind of use this to zoom in on where we need to focus. And if I look, well, while front is clear looks right, but this is a while condition.
And if you remember, we need to have a semicolon. After our while conditions, so we don't have that there. Okay, so now let's take a look where we set our code Again, this code is really just trying to build a staircase. We have a put ball We're doing this while front is clear loop and then we are running up and creating a step each time So let's try that now. Oh and it says error Named term right is not defined.
So when we use a command that is not present and Carol doesn't know This is the error that we get. So it says turn right is not defined. Well, it turns out we're not using supercarrow here, so we have to actually define that command.
So let's define turn right. Okay, and then that is just going to be three turn lefts. Okay, and so now if we run that. We should see Carol creating our staircase.
And there we go. So Carol has created our staircase. So again, we can use our errors. You know, if we have errors like this, it gives us an idea of where our line is.
When we have a command that Carol doesn't know, we're seeing something like this where it says, okay, turn let is not defined. And so that tells us we're giving Carol a bad command. So now it's your turn to go ahead and debug.