Hi, everyone. Welcome back. In this video, we are going to discuss how we handle exception. In our vocabulary builder app, we have a function to allow user entering the worse, less great than we create a function do well. We can use input and assign to values, input and new work. New work consists of the work itself, and the definition and the hand.
We want the user to input all three of them and have a separator between them. And then within two arrows, just see how it goes. Let's try that new word and our new one fun Admission is pressure and enjoyment or and payment and on the score on the score and yeah, it printed me the variables the value is a long tax, which is hard for us to handle. So, we are going to use the spring function to help on it to use the split function, let me go to the new function again. But now we are going to add functions and then put a separator so it will take too long tans separated by the separator. So in our cases, it will give me for you battles.
So let me create the variables to store them. Word, definition hand and we need to To print statement, so we have the first placeholder, and then are the placeholder. Next slide some space and a third placeholder and do a format. The first period, we want to put in the word itself. The second one we put in the hands. The first one we put in the definition.
So let's try that again. The word fun. Tasha and join Lin or end thing. Yeah. Now come to the key part of this video. The exception handling programs may get over and exist.
For example, we do try the new word again. Now, we put in And then we forget to put in the definition, and then we get a hand, and then we enter, we get a exception. Variables are not enough variables to unpack, because we only provide two barrels, but we have free variable so so there's an exception. However, the program exit, which is not what we want, so we should tell our user the input is wrong, instead of just exit the program. So let's try to improve the function again. So let's try to improve the function instead of just one that we put in a try.
And then we take to include we printed and then we have to accept cause. That means the following code will be one when there's exception when there's something wrong, please make sure your format is correct. If our value is correct if we run the tripod, unable to see if there is some problem maybe john today except Part A will print the statement. Please make sure your format is correct. But this is still not perfect because there could be other kinds of problems besides the format problems. So you can see the problems we have caught previously is very, there could be others and we should space different message for different kind of bearer.
Let's do that. Because we know the URL is very URL from the URL messages. So, in after the exam, we put in exam where the URL. That means if we get any new URL, we will run the code under it. And then for the kinds of error and we praying Something is wrong. This is how we use try except to help us implementing a function to add words to our vocabulary build the app.
In next video, let's complete the whole application. See you