1 00:00:00,520 --> 00:00:06,700 All right, now it is time to talk about Iraq handling's in by now, the first thing there is something 2 00:00:06,700 --> 00:00:13,960 called the unbooked function in Python, which is like this in but up in the brackets inside it. 3 00:00:13,960 --> 00:00:15,060 But the prompt message. 4 00:00:15,070 --> 00:00:18,940 So please enter evalu. 5 00:00:20,540 --> 00:00:26,760 On its do this and then we can print this value. 6 00:00:26,810 --> 00:00:32,210 OK, but actually the store that inside aFunction, which is inside the variable, I mean, and it's 7 00:00:32,210 --> 00:00:40,400 print the X like this so you can see this will receive an integer value or actually this is if you want 8 00:00:40,410 --> 00:00:44,930 to see it, it is a string value actually, but we will print it out. 9 00:00:44,960 --> 00:00:47,120 OK, so let's run this command. 10 00:00:47,570 --> 00:00:53,800 I mean, the men did buy one, which is the Biton, so please enter a value I would put or I will enter. 11 00:00:54,290 --> 00:00:54,740 Hello. 12 00:00:55,790 --> 00:00:58,880 And you can see it now if this help has been printed. 13 00:01:00,170 --> 00:01:03,620 But by the way, you can bet to be more elegant, actually. 14 00:01:04,630 --> 00:01:10,250 You can put it in here with the space and let's try again. 15 00:01:10,840 --> 00:01:12,180 So, yeah, you can see it now. 16 00:01:12,190 --> 00:01:13,060 It is more elegant. 17 00:01:13,080 --> 00:01:17,990 Please, you and I will put it on or whatever. 18 00:01:18,400 --> 00:01:19,720 OK, so this is it. 19 00:01:19,930 --> 00:01:21,030 OK, good. 20 00:01:21,070 --> 00:01:21,900 So far, so good. 21 00:01:23,360 --> 00:01:29,780 Now, let's return here and let's this time let's put another value, so twelve, yeah, it would give 22 00:01:29,780 --> 00:01:30,990 us 12 again. 23 00:01:31,400 --> 00:01:34,100 What if I couldn't hear some? 24 00:01:35,090 --> 00:01:39,300 Yeah, everything is working correctly now this time. 25 00:01:39,350 --> 00:01:42,410 What if I used the integer value like. 26 00:01:43,580 --> 00:01:46,950 So I want this value to be entered as an integer. 27 00:01:47,110 --> 00:01:57,110 OK, so I'm using the integer converter function, so anything we enter here must be integer or if not 28 00:01:57,110 --> 00:01:59,400 integer, I will convert it. 29 00:01:59,490 --> 00:02:03,520 OK, so let's run this and see into a value. 30 00:02:03,530 --> 00:02:07,060 If I typed it, you can see that it is wrong. 31 00:02:07,190 --> 00:02:07,610 Why? 32 00:02:07,970 --> 00:02:11,740 Because invalid literally for and would based in a. 33 00:02:12,200 --> 00:02:18,950 But again, if I run that and if I Rin Tin Tin is acceptable because this is an integer but if I run 34 00:02:19,430 --> 00:02:23,090 or what any string value or any value rather than int. 35 00:02:24,090 --> 00:02:32,640 It will show us this, OK, by the way, if I take ten point five, it will give us a road as well because 36 00:02:32,640 --> 00:02:33,920 this is a float value. 37 00:02:34,530 --> 00:02:36,570 The value must be integer only. 38 00:02:36,840 --> 00:02:37,220 OK. 39 00:02:37,640 --> 00:02:39,120 OK, so far, so good. 40 00:02:39,150 --> 00:02:45,050 Now, how to do such a thing without error, without putting this on. 41 00:02:45,450 --> 00:02:47,870 So we want the error to be handed. 42 00:02:47,880 --> 00:02:49,470 OK, we don't need to print. 43 00:02:49,870 --> 00:02:50,480 There are. 44 00:02:50,610 --> 00:02:51,510 This is not elegant. 45 00:02:51,840 --> 00:02:53,650 We need an elegant solution. 46 00:02:53,670 --> 00:02:54,300 How to do that. 47 00:02:54,300 --> 00:02:55,550 We would use that right. 48 00:02:55,590 --> 00:02:57,880 Except which is the error handling in Python. 49 00:02:58,140 --> 00:03:01,820 So how to do that by using tried to I what. 50 00:03:01,830 --> 00:03:02,520 Try this. 51 00:03:03,430 --> 00:03:12,710 OK, now, if there are errors or something, except so as you can see, these are inside the tri indentation. 52 00:03:12,910 --> 00:03:13,840 So except. 53 00:03:15,840 --> 00:03:17,550 And David Cooptation. 54 00:03:18,800 --> 00:03:24,930 And on here, I mean, if they are, let's print, for example. 55 00:03:24,950 --> 00:03:28,390 Oh, no, there is an error. 56 00:03:29,510 --> 00:03:32,180 OK, and I think this is just a better example. 57 00:03:32,210 --> 00:03:38,360 OK, so if I try this again when I enter 10 or any integer value, it works fine. 58 00:03:38,750 --> 00:03:43,190 OK, so let's clear the screen and let's try enter high, for example. 59 00:03:43,730 --> 00:03:45,110 Yeah, you can see that. 60 00:03:45,320 --> 00:03:46,450 You can see now it is. 61 00:03:46,460 --> 00:03:47,840 Oh no there is an error. 62 00:03:47,920 --> 00:03:51,070 OK, so it handled the error with elegant way. 63 00:03:51,110 --> 00:03:57,490 So if there are error here, not like before, before it will give us what is the error. 64 00:03:57,500 --> 00:03:59,140 And actually this is bad. 65 00:03:59,520 --> 00:03:59,960 No. 66 00:03:59,990 --> 00:04:03,980 This time if we face any error, actually it will. 67 00:04:05,340 --> 00:04:12,600 Brent, this statement, or it will do these things inside the accept, so, for example, your value 68 00:04:12,780 --> 00:04:19,200 that has been entered as negative, you can inside that, except you can put it or use the absolute 69 00:04:19,200 --> 00:04:26,790 function, the apps and convert it to something positive, and then you can assign it to the value you 70 00:04:26,790 --> 00:04:27,120 want. 71 00:04:27,150 --> 00:04:29,160 OK, well, actually it has a lot of use cases. 72 00:04:29,280 --> 00:04:32,300 You can read about it if you are interested in it. 73 00:04:32,340 --> 00:04:35,610 Actually, if you open your browser and you go or type. 74 00:04:36,650 --> 00:04:39,410 Python is right, except. 75 00:04:40,700 --> 00:04:47,900 Then you can go to the three schools dot com and here you can see that there are a lot of examples and 76 00:04:47,900 --> 00:04:55,670 not just to try, except there are another format, which is that you can put arrays then in error and 77 00:04:55,670 --> 00:04:57,710 another other errors actually you can see. 78 00:04:57,890 --> 00:05:00,670 So try to accept them. 79 00:05:01,040 --> 00:05:02,660 OK, and Brent. 80 00:05:02,660 --> 00:05:04,740 And then finally accept this, OK? 81 00:05:05,060 --> 00:05:08,900 So actually there are other formats like that using the Elsah as well. 82 00:05:09,200 --> 00:05:13,040 So you can see try these printed or accept something else. 83 00:05:13,490 --> 00:05:19,910 We have the finally and here you can see that it will be raised as you can see it, except Pindi. 84 00:05:20,210 --> 00:05:23,180 So this will try to accept after it is finished. 85 00:05:23,180 --> 00:05:29,110 And you can see there are a lot of examples here if you are interested to have or to learn more about 86 00:05:29,120 --> 00:05:29,300 it. 87 00:05:29,570 --> 00:05:38,240 OK, but anyway, it's not that big a deal to know everything, but just know that there are other format 88 00:05:38,240 --> 00:05:39,470 and other use cases. 89 00:05:39,800 --> 00:05:41,290 You can read more about it. 90 00:05:41,300 --> 00:05:45,860 But for now, keep in mind this is the way to handle the errors in Python. 91 00:05:46,250 --> 00:05:47,090 Thanks for watching.