1 00:00:11,560 --> 00:00:12,310 Hi there. 2 00:00:12,870 --> 00:00:19,190 I think it's a good time to try to resolve these three meaning assignments, so let's do it. 3 00:00:19,420 --> 00:00:27,040 Basically, what I'm going to do now is just copy all of these three parts, open bicarb and go to piece 4 00:00:27,040 --> 00:00:28,630 them right here. 5 00:00:29,110 --> 00:00:31,450 And basically we have three separate assignments. 6 00:00:31,450 --> 00:00:38,470 So first of all, let me just write a comment here, which is exceptions. 7 00:00:41,920 --> 00:00:50,380 There's practice and also here just going to change the name of the file to. 8 00:00:51,910 --> 00:00:55,480 Exceptions, heroes practice. 9 00:01:01,970 --> 00:01:02,510 Like that. 10 00:01:03,650 --> 00:01:12,560 All right, so just going to do to market and do control, backslash and also control backslash to that 11 00:01:12,560 --> 00:01:15,830 part and we're just going to try to resolve the first one. 12 00:01:16,400 --> 00:01:18,500 OK, so this is the code that we have. 13 00:01:18,680 --> 00:01:22,460 If we write as is, we're going to have an exception. 14 00:01:22,790 --> 00:01:23,270 All right. 15 00:01:23,270 --> 00:01:30,000 So we having a casting exception, which we are very much familiar with, and we're going to put all 16 00:01:30,020 --> 00:01:32,080 this code inside. 17 00:01:32,090 --> 00:01:32,600 Try. 18 00:01:34,320 --> 00:01:44,220 Like that, and then we're going to use except to basically resolve this issue and we're going to right 19 00:01:44,220 --> 00:01:48,390 here to the end user, that casting was not. 20 00:01:50,690 --> 00:01:52,730 Made for the. 21 00:01:55,020 --> 00:01:57,060 For the president of X. 22 00:01:57,940 --> 00:02:00,930 OK, and right now we're going to do print. 23 00:02:03,190 --> 00:02:11,260 The number is and then we're going to put percentages and then percentage X. 24 00:02:12,500 --> 00:02:22,460 Like that, yeah, but we're having an additional issue here, I think that X is not recognized, it's 25 00:02:22,460 --> 00:02:23,240 undefined. 26 00:02:23,240 --> 00:02:26,260 All right, because we define the X in the try. 27 00:02:27,260 --> 00:02:29,240 We cannot use it inside the except. 28 00:02:29,510 --> 00:02:35,800 So we have two options, OK, because the accepters not familiar with what happens inside the tri. 29 00:02:36,080 --> 00:02:37,460 So we have two two options. 30 00:02:37,460 --> 00:02:43,640 We either can declare it again inside the ship, which is a worst, uh, solution. 31 00:02:43,910 --> 00:02:49,570 But the better solution is just to define it, defined it outside of try and accept. 32 00:02:49,700 --> 00:02:53,750 And that way they both are going to have access to it like that. 33 00:02:54,650 --> 00:02:55,220 All right. 34 00:02:56,870 --> 00:02:59,090 Um, let's run it now. 35 00:03:01,400 --> 00:03:03,330 All right, there you go. 36 00:03:03,710 --> 00:03:09,750 So you have this X defined outside the tri accept statement, then we had a failure. 37 00:03:10,000 --> 00:03:17,030 So the code immediately went to accept and you can see casting was not made for print of X, the number 38 00:03:17,030 --> 00:03:18,280 is five, OK? 39 00:03:18,530 --> 00:03:24,380 And I also want to show you that whatever comes after the except for example, we have print ABC here 40 00:03:24,650 --> 00:03:25,640 will also run. 41 00:03:25,760 --> 00:03:26,240 All right. 42 00:03:26,370 --> 00:03:32,750 So you can see ABC also is being run, even though it's outside the except because everything comes 43 00:03:32,750 --> 00:03:34,700 after the acceptable run perfectly. 44 00:03:34,820 --> 00:03:35,240 All right. 45 00:03:36,590 --> 00:03:39,500 So that was our assignment. 46 00:03:45,400 --> 00:03:48,290 Simon one, and we have completed it. 47 00:03:48,310 --> 00:03:59,890 All right, now we're going to handle with assignment to let's also put here print special key keyword 48 00:03:59,890 --> 00:04:03,460 and solve the printouts right here would be divided with spaces. 49 00:04:03,910 --> 00:04:11,890 So we have this statement of X basically that let's make it a Y, OK, because X is defined for us and 50 00:04:11,890 --> 00:04:14,780 we're basically trying to resolve it in the same file. 51 00:04:14,980 --> 00:04:21,670 So if printing making X plus five, nothing will go wrong because we already have X here, but it's 52 00:04:21,670 --> 00:04:23,880 in a different assignment. 53 00:04:23,890 --> 00:04:25,540 OK, they are separate assignments. 54 00:04:27,730 --> 00:04:33,970 So we have this Y plus five and once we run it, we're having an exception. 55 00:04:34,240 --> 00:04:42,040 Name Y is not defined OK, because we did not define Y and we also are going to put it in so dry with 56 00:04:42,040 --> 00:04:51,760 intention right here and then except going to have y was not defined. 57 00:04:53,560 --> 00:04:56,260 Name error was raised. 58 00:04:58,080 --> 00:05:06,630 And now we're going to also defined why as well as we did before, y equals to one doesn't matter. 59 00:05:06,680 --> 00:05:06,950 Yeah. 60 00:05:10,440 --> 00:05:17,540 And now we can do Y plus five and then print Y plus five. 61 00:05:17,700 --> 00:05:18,090 Yeah. 62 00:05:22,090 --> 00:05:26,110 So what do you have here, stateman have no effect. 63 00:05:26,220 --> 00:05:27,340 Oh, yeah, no problem. 64 00:05:28,470 --> 00:05:31,090 Let's do, for example, result. 65 00:05:33,580 --> 00:05:40,030 Like that, yeah, as long as we're not raised, with an exception with why plus five, this is the 66 00:05:40,030 --> 00:05:43,170 meaning of the assignment to avoid the exception. 67 00:05:44,320 --> 00:05:48,670 So no number is five. 68 00:05:48,680 --> 00:05:51,070 We have but this printout we do not have. 69 00:05:52,120 --> 00:05:52,850 And why is that? 70 00:05:52,870 --> 00:05:54,580 Let's try to investigate. 71 00:05:56,350 --> 00:06:03,490 Oh, so obviously, huh, I see what happened here, obviously, if I declared why outside the scope 72 00:06:03,490 --> 00:06:07,620 of dry except so now we do not have an exception inside dry. 73 00:06:07,630 --> 00:06:11,800 OK, this line does not cause an exception which is going to prove it to you. 74 00:06:12,760 --> 00:06:20,620 We're going to put Brent A.B.C. here so we're not having any exception in here. 75 00:06:21,790 --> 00:06:27,700 Yeah, you can see ABC because we have declaration of way, so we basically aborted the mission. 76 00:06:28,030 --> 00:06:34,030 So we're going to remove the Y equals one here because we do want to have an exception inside the tray 77 00:06:34,210 --> 00:06:36,700 and we do want it to go inside the except. 78 00:06:36,970 --> 00:06:40,630 So we're going to put Y equals one right here like that. 79 00:06:41,840 --> 00:06:43,070 Oops, wrong button. 80 00:06:44,690 --> 00:06:52,510 Yeah, so now we are getting what we wanted, why was not defined name or was was raised and then we're 81 00:06:52,520 --> 00:06:57,930 printing of one of Y plus five and we're getting the result right here. 82 00:06:57,950 --> 00:06:59,750 So this one also was handled. 83 00:07:00,050 --> 00:07:07,730 And now we're going to do this one assignment to now we're going to resolve assignment number three, 84 00:07:08,630 --> 00:07:09,590 which is this one. 85 00:07:10,700 --> 00:07:14,870 Let's remove the last note. 86 00:07:15,060 --> 00:07:15,500 Right. 87 00:07:15,770 --> 00:07:18,110 And we're going to try and here. 88 00:07:18,620 --> 00:07:18,980 Right. 89 00:07:20,840 --> 00:07:28,340 And except and this what's going to raise an error right here is unexpected. 90 00:07:28,340 --> 00:07:29,930 EDF, what is it? 91 00:07:30,870 --> 00:07:32,150 We don't have anything here. 92 00:07:37,080 --> 00:07:46,460 OK, so now we're not having we having an error here, you can see that cold is not going to reach. 93 00:07:47,730 --> 00:07:51,510 Code is not going to reach, but this line right here. 94 00:07:53,880 --> 00:08:00,580 All right, because it fails over here, OK, fails over here and you can see it in your own eyes. 95 00:08:00,600 --> 00:08:05,520 Let me just I'm just doing some experiments intentionally so you can see all the behaviors. 96 00:08:05,530 --> 00:08:05,850 Yeah. 97 00:08:06,210 --> 00:08:07,150 Yeah, there you go. 98 00:08:07,500 --> 00:08:09,640 So we having several errors here. 99 00:08:10,050 --> 00:08:17,610 First one is here, but that actually is not relevant. 100 00:08:17,860 --> 00:08:23,970 It shows us the reason is it shows us all the exceptions that happened because we're having one exception 101 00:08:23,970 --> 00:08:27,750 here and it basically shows us all the exception that happen. 102 00:08:28,020 --> 00:08:34,790 But if we divide it into three files, OK, let's do a practice exception. 103 00:08:37,120 --> 00:08:38,080 Practice one. 104 00:08:40,560 --> 00:08:43,230 And then we're going to break exception practice to. 105 00:08:47,300 --> 00:08:53,210 And I'm going to have exception brought these three, we're going to divide these three examples into 106 00:08:53,210 --> 00:08:55,650 three, we would not get this error. 107 00:08:56,030 --> 00:09:02,270 OK, so we're going to put this assignment three in file three and we have assignment two. 108 00:09:02,270 --> 00:09:06,530 We're going to leave here an assignment one we're going to put in here. 109 00:09:06,880 --> 00:09:09,290 OK, so you see what I did here? 110 00:09:09,290 --> 00:09:16,030 I said each assignment of its own file and we're going to run the first one, OK? 111 00:09:16,040 --> 00:09:19,580 We're perfectly going to run the second one, which we already did 112 00:09:22,610 --> 00:09:22,960 up. 113 00:09:25,470 --> 00:09:34,290 Run also runs perfectly, and only this one will fail once you run it and you can see indention error 114 00:09:34,680 --> 00:09:38,630 first if we remove the indention. 115 00:09:39,060 --> 00:09:47,580 We also are going to have index error because we were having index six here while having only index 116 00:09:47,640 --> 00:09:49,450 three, last one in the list. 117 00:09:49,920 --> 00:09:58,170 So this one we're going to also put inside try and right here we're going to set list. 118 00:09:59,220 --> 00:09:59,850 You know what? 119 00:09:59,850 --> 00:10:01,080 Let's take the list. 120 00:10:01,080 --> 00:10:02,130 Put it outside. 121 00:10:02,140 --> 00:10:08,850 Yeah, this is the most effective way instead of declaring it once and once and except it right here, 122 00:10:08,850 --> 00:10:16,140 we're going to do a print list three, OK, three, which is the last one, the last index inside of 123 00:10:16,140 --> 00:10:16,560 the list. 124 00:10:16,800 --> 00:10:18,300 And we're going also to write. 125 00:10:19,260 --> 00:10:20,970 Tried to. 126 00:10:24,490 --> 00:10:32,380 Pool index six, while only three are valuable. 127 00:10:35,780 --> 00:10:44,300 Yeah, and now if we run it, you can see the the run of the cold went into accept and basically ignored 128 00:10:44,300 --> 00:10:47,750 this sprint x x because we had an exception right here. 129 00:10:47,930 --> 00:10:51,290 And you can see that no error happened in the execution. 130 00:10:51,540 --> 00:10:52,650 Everything's OK. 131 00:10:52,820 --> 00:10:55,850 The code is keeping its execution. 132 00:10:55,970 --> 00:11:02,750 Even though we have an error here because we wrapped it, we're dry accept and it went straight over 133 00:11:02,750 --> 00:11:03,700 to the airport. 134 00:11:04,190 --> 00:11:04,690 All right. 135 00:11:04,700 --> 00:11:08,570 So this concludes are the exception and our handling as well. 136 00:11:08,750 --> 00:11:10,400 I will see you in the next video. 137 00:11:10,460 --> 00:11:11,000 Thank you.