1 00:00:00,060 --> 00:00:02,320 Welcome to another video of our pipeline lessons. 2 00:00:03,120 --> 00:00:09,930 Today, we are going to talk about the try and accept statement, try and accept is very useful in case 3 00:00:09,930 --> 00:00:11,640 we want to try a block of code. 4 00:00:11,940 --> 00:00:17,430 But we also know that we might get an error for any reason, and that error will cause our program to 5 00:00:17,430 --> 00:00:17,940 crash. 6 00:00:19,200 --> 00:00:24,600 Let's create a wireless program that should be working unless we interrupt the program using control. 7 00:00:24,600 --> 00:00:24,960 See? 8 00:00:32,440 --> 00:00:38,800 This program takes input from the user using the raw input function, then we split it using the split 9 00:00:38,800 --> 00:00:41,350 function and we get the first and second element. 10 00:00:41,950 --> 00:00:43,810 Then finally we printed. 11 00:00:58,920 --> 00:01:05,910 This program should keep running, but what happens if we provide only one string, then the second 12 00:01:05,910 --> 00:01:13,800 string, this line won't work and it should give us an error because it will try to fix something that 13 00:01:13,800 --> 00:01:14,970 simply doesn't exist. 14 00:01:15,960 --> 00:01:16,830 Let's try that. 15 00:01:25,260 --> 00:01:31,710 As you noticed, we got to hear the name of the errors called index error, followed by a short description 16 00:01:31,710 --> 00:01:32,680 of the better. 17 00:01:33,660 --> 00:01:34,840 That's all we need from now. 18 00:01:35,790 --> 00:01:42,180 Now, let's tell our program to expect something like that and deal with it using the try and accept 19 00:01:42,600 --> 00:01:43,020 Buck. 20 00:01:47,760 --> 00:01:54,210 First, we execute the block of code that we know we might get an error from under the TRAI statement, 21 00:01:59,190 --> 00:02:02,010 let's invent all the lines. 22 00:02:06,750 --> 00:02:10,140 Then after the block, we must provide an exception. 23 00:02:11,010 --> 00:02:13,410 We do that by typing the word accept, 24 00:02:19,800 --> 00:02:25,830 but if we only provide the word except, then our program will deal with any type of error in general 25 00:02:25,830 --> 00:02:28,770 and it will jump into this line, would it, when it occurs? 26 00:02:50,130 --> 00:02:54,540 Now, let's be more specific and provide which type of where we want to deal with. 27 00:02:59,080 --> 00:03:06,400 From before we know that there was we received this called indexer, so let's specify that after the 28 00:03:06,400 --> 00:03:07,210 word, except 29 00:03:15,400 --> 00:03:19,840 we can also get the description of the air that will help us in our troubleshooting later. 30 00:03:20,500 --> 00:03:25,960 We can do that by using the word as followed by the variable name that we will store the air in. 31 00:03:29,590 --> 00:03:34,750 Now our air will be stored in the variable E. We can also print it. 32 00:03:53,790 --> 00:03:54,310 Nice. 33 00:03:55,500 --> 00:04:02,730 We can also use the Elst statement in the trial, except block, the statement will be executed if nothing 34 00:04:02,730 --> 00:04:06,600 went wrong with the tribe block, but we still want to execute. 35 00:04:27,810 --> 00:04:33,360 We can also use the finally block, which it will be executed regardless of the try block raises in 36 00:04:33,360 --> 00:04:34,350 here or not. 37 00:05:00,680 --> 00:05:04,100 Now, let's try it both within here and without error. 38 00:05:15,890 --> 00:05:19,690 As you noticed, the final block was executed in both times. 39 00:05:21,470 --> 00:05:23,090 We have reached the end of this lesson. 40 00:05:23,360 --> 00:05:23,930 Thank you. 41 00:05:23,930 --> 00:05:25,040 And see you in the next one.