WEBVTT 00:01.250 --> 00:08.260 Welcome in this lecture, I'm going to build a program that will handle errors properly, OK, stop. 00:09.990 --> 00:15.330 They say that the program will receive an age value as an argument from the command line like this, 00:15.720 --> 00:18.360 a choice that marks the first argument. 00:19.420 --> 00:19.870 OK. 00:20.960 --> 00:26.950 Here, ages type is drink, so I need to convert it to an integer before I can use it, right. 00:27.740 --> 00:35.990 So let's convert it using a TOI function like this and hour short, declare Starcom a two I h. 00:36.800 --> 00:44.030 As you can see, I see the returned values from this function into two variables and are most of the 00:44.030 --> 00:48.080 time and error value is saved into a variable names error is in here. 00:49.610 --> 00:55.490 Is it not from the previous lecture that if the user passes a non numeric number eight to able to return 00:55.490 --> 00:55.900 an error? 00:55.910 --> 00:56.260 Right. 00:56.810 --> 01:00.830 So now it is time to check for that within a simple if statement like this. 01:01.860 --> 01:07.230 And as I said before, the air value would be in until one day to our function couldn't convert the 01:07.230 --> 01:08.070 past value. 01:09.070 --> 01:14.440 So here I'm checking whether there was an error or not by comparing the error variables value with a 01:14.440 --> 01:15.020 new value. 01:15.730 --> 01:18.950 Remember, nominal value means there is an error. 01:19.540 --> 01:24.610 So this branch will only be executed when the user passes a non numeric value. 01:27.150 --> 01:32.460 Now, let's display the returned air value like this printer error. 01:33.730 --> 01:35.610 I'm going to pass to everybody, OK? 01:36.790 --> 01:43.660 Let's quit from the main function just by returning from it like this, OK, value call a function that 01:43.660 --> 01:44.650 returns an error. 01:44.800 --> 01:50.320 You should always check for the error immediately after the call to that function, as I did so here. 01:50.590 --> 01:54.910 OK, so you shouldn't do anything else before checking for the error. 01:55.310 --> 02:01.060 It's because you may create unintentional bugs in your software if you don't check for the errors immediately. 02:02.020 --> 02:08.590 All right, now let's print another message about that, the commercial my successful like this print 02:08.650 --> 02:09.000 F. 02:09.730 --> 02:10.670 To success. 02:11.620 --> 02:12.490 Converted. 02:13.330 --> 02:17.140 Person to person to nearline. 02:18.030 --> 02:20.400 Now, I'm going to pass H on here. 02:20.640 --> 02:27.390 OK, so if the program reaches to this code line, that means the error value was near and so to add 02:27.390 --> 02:28.890 to our function was successful. 02:29.110 --> 02:29.460 OK. 02:30.530 --> 02:32.630 This is also known as the happy path. 02:33.140 --> 02:35.210 This is what we want from this program, right? 02:35.660 --> 02:39.830 So to convert the number without any problems, so that makes us happy. 02:40.100 --> 02:41.600 So it's called a happy. 02:41.600 --> 02:43.550 But let's right now. 02:45.870 --> 02:50.610 Let's run it with a proper numeric value like this, just 25. 02:52.600 --> 03:00.250 As you can see, Prince success, cool, as I said, this was the program Bapat, so there wasn't any 03:00.250 --> 03:00.610 error. 03:01.180 --> 03:04.210 The conversion was successful and the error, it was new. 03:05.250 --> 03:06.560 Now, let's run this program. 03:06.570 --> 03:14.510 It's an incorrect data like this example, it prints an error message is because now the error value 03:14.520 --> 03:15.160 wasn't nil. 03:15.300 --> 03:16.470 So there was an error. 03:17.340 --> 03:18.260 It was executed. 03:18.270 --> 03:19.260 This if statement. 03:20.210 --> 03:26.030 And then it has returned from the program here, so the happy part wasn't executed because there was 03:26.030 --> 03:26.420 another. 03:27.640 --> 03:34.000 So in summary, this is how we can handle errors Engo by using a simple if statement to check for whether 03:34.000 --> 03:38.110 that returned error value is nil or not, and that's all about it. 03:39.630 --> 03:41.200 All right, thank you for watching. 03:41.640 --> 03:42.710 See in the next picture.