Hello, welcome to the 65th tutorial in the c++ programming series, and in this part we'll be looking at error handling. c++ provides a means to handle runtime errors called exceptions, which allow an error to be detected within a certain block of code and routing the flow to another piece of code if an Erica instead of crashing, for example, if you try to load a file, the application could pick up an error which file didn't exist, and inform the user that the Father exists. This is useful obviously, because you do not want your application to crash. You just provide an alternate alternate route for your application. And setting this example is going to tell the user what's happened. So let's go ahead and open up our project.
And we're not going to actually create a class in this one. First, I'm going to create a class for wild foods, food, few tutorials, and only so the syntax is the key word Troy. Basically Saying, let's try some code, then you put curly braces and then in here you put the code that you want for error handling. So it's going to pop fro one. And for one just basically throws an error. And the reason we're going to throw an error explicitly is so you can see what happened.
But otherwise, you'll put something in here and if it failed, then he will just get into the catch block which we're going to implement now. Catch basically catches the error which we are explicitly going to throw that we know that an error occur. We're just going to put it error and this error will actually be one. If we do STD STD, the error can do STD and line wrap and we get one and that's okay. And you're moving on They understand a little bit but let's just try and give you a better example. So if you have a variable save it or make it equal to no and then put it in the Troy if it is less than 10 then it's a okay so we can perform some function acting.
So what we could do is just we're just gonna print out so STD alone. As we could throw this exception, we run out, we get nine but if we change this to 11 when we get one here's another better example looking at implemented was going to talk me in Division you don't be blind but zero if you put that into a calculator prior to that if you're not on time, you'll get an error. If you're doing an application, and if your application doesn't have the proper error handling for whether it's via try, catch block, or whether it's something else, just simple if else statements, your application will crash, what you could do here is do a try. And if you get an error or some sort of problem, you will cache the error, and then you won't do the division. So that's a pretty cool thing that you can do.
And that's it for this part of the series. The next part we're going to look at preprocessor macro definitions. If you have any questions, feel free to message us at support at signal systems code at UK email will be in the description you can comment on this video with historically messages via YouTube, or calling for source code will also be in the description and as usual, thanks for watching and hope you have a great day.