1 00:00:01,170 --> 00:00:05,820 By exceptionally dry, except and finally. 2 00:00:08,310 --> 00:00:16,140 Python has many built-In exceptions, which enables our program to output an error message when something 3 00:00:16,320 --> 00:00:17,660 is going wrong. 4 00:00:18,180 --> 00:00:21,870 So there are different mechanisms to help of such error. 5 00:00:21,870 --> 00:00:25,860 Messages can be generated whenever there is some error in the system. 6 00:00:26,490 --> 00:00:32,850 So when those exceptions occur, it causes the current process to stop and passes it to the calling 7 00:00:32,850 --> 00:00:33,420 process. 8 00:00:33,510 --> 00:00:38,930 And until it is handled, so if not handled, our program will crash. 9 00:00:39,450 --> 00:00:44,970 So for the better understanding on this concept, let us go for one practical example and to show you 10 00:00:45,180 --> 00:00:52,920 that how this trial except and finally are working now in this demonstration, we shall discuss more 11 00:00:52,950 --> 00:00:55,900 on these exceptions and errors in Python. 12 00:00:56,370 --> 00:00:58,860 So here to see here, we have having one tribe block. 13 00:00:58,860 --> 00:01:07,050 It is equal to 100, basically to twenty six to a baby B so here we are having one except block. 14 00:01:07,050 --> 00:01:10,220 That is the digital division error. 15 00:01:10,230 --> 00:01:14,850 So except on this JIRU division hatred and division, Brazil is not possible. 16 00:01:15,150 --> 00:01:17,960 But here to see the beat is having the value which is Longido. 17 00:01:18,210 --> 00:01:23,360 So we are expecting that this particular division, Giru Division error will not be raised. 18 00:01:23,550 --> 00:01:25,110 So let us go for the execution. 19 00:01:25,110 --> 00:01:29,550 You can find that this particular code has got not printed, so let us print it. 20 00:01:32,480 --> 00:01:39,380 So now if I go on executing, we can find that there's 100 by 26 to 5.0, so it is giving output because 21 00:01:39,380 --> 00:01:40,870 there is no error has occurred. 22 00:01:41,210 --> 00:01:47,810 But if I make this one, if I make this one as a zero, then obviously that division by zero is not 23 00:01:47,810 --> 00:01:53,750 possible that the control is coming directly from this particular line to this except block. 24 00:01:53,900 --> 00:01:59,960 And this particular statement is getting printed, which is written under the except Gedo deletion error 25 00:01:59,960 --> 00:02:00,350 block. 26 00:02:00,920 --> 00:02:04,910 So now you can find at that point about one exception is orcharding. 27 00:02:04,910 --> 00:02:10,070 Then from that line, the control is coming directly to the respective except block, and that is part 28 00:02:10,070 --> 00:02:14,440 of the code in the trade block will remain unreachable and aren't executed. 29 00:02:14,750 --> 00:02:17,090 So let us suppose I'm just writing this one in this way. 30 00:02:23,150 --> 00:02:29,990 OK, now if I go for the execution, I'm writing this one is 100, writing this one is 20, I'm getting 31 00:02:29,990 --> 00:02:30,350 dirty. 32 00:02:30,350 --> 00:02:31,500 Great output as well. 33 00:02:32,210 --> 00:02:38,650 So now if I go for the execution, you can find that I'm giving the ABC and giving the value. 34 00:02:38,670 --> 00:02:45,380 You see, when I'm writing this value ABC, I've given the ABC it cannot be converted to the to the 35 00:02:45,380 --> 00:02:48,170 indigent using the type conversion method. 36 00:02:48,170 --> 00:02:49,140 That is a.. 37 00:02:49,550 --> 00:02:50,740 So what is the error here? 38 00:02:50,810 --> 00:02:52,210 It is evaluated. 39 00:02:52,580 --> 00:02:56,080 So that's why I can also go for the value error here. 40 00:02:56,330 --> 00:02:57,890 So now I can raise here. 41 00:02:57,890 --> 00:02:59,390 So I'm writing one except. 42 00:03:06,000 --> 00:03:11,580 The detectives are not proper, so I've given this evaluator here, so now if I execute my code and 43 00:03:11,580 --> 00:03:17,940 if I get 100 and then ABC, you can see I'm getting the this particular statement got printed. 44 00:03:18,180 --> 00:03:20,260 That is the data types are not proper. 45 00:03:20,700 --> 00:03:27,990 So if I execute and if I put ABC at the first, then also it is this particular evaluator will be caught 46 00:03:27,990 --> 00:03:28,210 here. 47 00:03:28,650 --> 00:03:34,710 So you see, whenever you are performing this conversion to integer and whenever I'm giving the input 48 00:03:34,710 --> 00:03:37,960 string as ABC, ABC cannot be converted to integer. 49 00:03:38,100 --> 00:03:40,780 So that's where the data types are not proper. 50 00:03:40,800 --> 00:03:46,810 This particular statement is getting printed because the content is coming directly to this except valuated. 51 00:03:47,010 --> 00:03:52,730 So it is not going for this JIRU division either, because that exception, that error is not happening. 52 00:03:53,130 --> 00:03:54,990 So let us go for another one. 53 00:03:55,140 --> 00:04:00,030 I'm going for the I want to have one restriction on this eight. 54 00:04:00,510 --> 00:04:03,660 So I'm just writing this one if it's. 55 00:04:04,780 --> 00:04:08,260 If it is below this zero. 56 00:04:09,220 --> 00:04:12,100 That means if it is negative, then I shall have one. 57 00:04:13,890 --> 00:04:17,370 Raise say I'm going for the animators, a typedef. 58 00:04:19,830 --> 00:04:23,850 OK, so I'm just writing this one race type error, so here. 59 00:04:29,360 --> 00:04:32,120 OK, so now what will happen, see? 60 00:04:33,520 --> 00:04:37,990 And putting the value one hundred and twenty, it is giving me the outcome. 61 00:04:39,500 --> 00:04:45,710 I'm giving the value minus 90 and giving the value says 16, I'm getting the output output that the 62 00:04:45,710 --> 00:04:47,310 data is not in range. 63 00:04:47,600 --> 00:04:51,300 So in this way, also, we can raise your type here. 64 00:04:51,320 --> 00:04:51,680 Here. 65 00:04:52,310 --> 00:04:54,010 So now I'm doing another check. 66 00:04:54,020 --> 00:04:58,640 I'm just going for X, Y, Y, you see X and Y, they are not defined here. 67 00:04:58,880 --> 00:05:02,990 Then what will happen if I go on executing it is asking for the value. 68 00:05:03,020 --> 00:05:04,340 So let me give the values. 69 00:05:04,490 --> 00:05:08,410 And now it is raising one error that is animated, it is raising money. 70 00:05:08,540 --> 00:05:10,130 That is the X is not defined. 71 00:05:10,520 --> 00:05:14,380 So that that means I should go for I should go for another one. 72 00:05:14,390 --> 00:05:15,260 There is a limited. 73 00:05:19,230 --> 00:05:26,400 So data items are not defined, so that is my respected Blocher Britain print data items are not defined. 74 00:05:26,430 --> 00:05:33,270 So now if I go on executing so these values and providing no issues, but it is producing the it is 75 00:05:33,270 --> 00:05:38,820 the is coming to this except limited and this particular statement is getting printed that the data 76 00:05:38,820 --> 00:05:40,410 items are not defined. 77 00:05:40,800 --> 00:05:45,810 So in this way, in this particular demonstration, you can find that one trade block can be followed 78 00:05:45,810 --> 00:05:47,520 by multiple exit blocks. 79 00:05:47,670 --> 00:05:53,080 And depending upon the result, depending upon the error type, which will be raised within the trade 80 00:05:53,100 --> 00:05:59,400 block, accordingly, the respective exit block will be executed and this part of the trade block will 81 00:05:59,400 --> 00:06:01,680 remain unreachable and unexpected. 82 00:06:02,280 --> 00:06:03,510 Thanks for watching this video.