WEBVTT 00:00.150 --> 00:00.900 Welcome back. 00:01.110 --> 00:04.860 In this lecture, I'm going to show you how to handle the errors with examples. 00:06.100 --> 00:12.010 If you're coming to go from other languages, you may be surprised that God doesn't have to catch statements 00:12.010 --> 00:16.600 or exceptions in the usual sense, as I showed you in the last lecture. 00:16.640 --> 00:23.050 We go first, use a simple if statement to check for the errors explicitly because it's more readable 00:23.050 --> 00:27.160 and bugs cannot hide under the buggy code or inside a troll cat statement. 00:27.860 --> 00:28.860 Let's check it out now. 00:30.590 --> 00:34.070 Engo Some functions always work without any errors. 00:34.850 --> 00:39.980 For example, let's take a look at the ETA app function from the Starcom package. 00:42.790 --> 00:43.880 You've seen it before. 00:43.930 --> 00:48.940 It just takes an intaglio and an argument and converts it to a string rather than returns it. 00:49.480 --> 00:53.560 OK, this function always succeeds and it never fails. 00:54.020 --> 00:58.630 It's because an integer can always be converted to a string value no matter what. 00:59.470 --> 01:02.720 There is no need to return an error from this function. 01:03.640 --> 01:09.550 So since this function return error values, so you don't need to handle any errors when you call it. 01:12.120 --> 01:16.020 OK, now let's take a look at an example, got to understand this better. 01:20.760 --> 01:25.770 Let me call this the article that I took by passing it an integer value like this. 01:26.780 --> 01:27.370 Forty two. 01:28.060 --> 01:33.830 OK, I'm going to say the result of this function into the swayable, which is a shrink, since it's 01:33.840 --> 01:35.330 our function, returns a string. 01:36.370 --> 01:40.480 Let's take a look at the documentation of this function again to better understand how it works. 01:40.910 --> 01:43.930 As I showed you before, it takes any value as an argument. 01:43.930 --> 01:45.210 And this is incredible. 01:45.580 --> 01:46.810 OK, it's that simple. 01:47.500 --> 01:47.970 All right. 01:47.980 --> 01:49.210 Let's bring the result now. 01:52.100 --> 01:53.330 OK, renters are. 01:56.730 --> 02:03.200 As you can see, just prince it to as a swink, nothing interesting here so far, but now you've seen 02:03.210 --> 02:08.580 that you don't need to handle any errors for this function because it doesn't provide an error value 02:08.580 --> 02:09.530 for you to check. 02:09.540 --> 02:10.890 It always succeeds. 02:12.420 --> 02:16.020 Now, let's take a look at another function which returns an error value. 02:19.430 --> 02:21.770 Here is another function from a Starcom package. 02:22.710 --> 02:31.380 A to I means as key to integer, you can think of ASCII as a string value, so it takes a string value 02:31.380 --> 02:35.910 and it tries to convert it into an hourly pay attention to my work. 02:35.940 --> 02:39.420 Now it tries so it doesn't always succeed. 02:40.960 --> 02:47.470 As you can see here, that's why it also returns an air value, that error, rather, tells us about 02:47.470 --> 02:51.790 whether the conversion from the street value to int value is successful or not. 02:52.740 --> 02:56.820 As I said, this function doesn't always return a successful result. 02:57.240 --> 03:04.740 It may fail, and when it does so, you should never use the return value from this function because 03:04.740 --> 03:07.800 the returned value may be in an undefined state. 03:09.050 --> 03:12.740 It's probably going to be a value which you didn't expect. 03:13.890 --> 03:17.610 But in the case of a two hour function, it returns zero as an error. 03:18.880 --> 03:22.010 So it doesn't matter actually whether you check the air or not. 03:22.150 --> 03:26.600 I'm just showing it to you here as an example for handling errors. 03:26.860 --> 03:28.150 It's just a simple example. 03:29.700 --> 03:32.740 OK, now let's take a look at its value. 03:33.750 --> 03:40.200 When it returns a new air value, it means that the function is successful so you can use the converted 03:40.200 --> 03:40.830 into value. 03:41.070 --> 03:47.670 OK, otherwise when it returns a nominal at our value, it means that the conversion has been failed 03:47.670 --> 03:50.730 and it couldn't convert the past value to an integer. 03:51.850 --> 03:57.520 Let me show you this function in the coding, Ed, as an example so you can understand it better. 04:00.280 --> 04:03.190 Let's first call the A to our function like this. 04:05.670 --> 04:08.190 And let's pass it a command line arguments. 04:12.540 --> 04:16.710 As you can see here, it returns on its value and an NRL rights. 04:18.190 --> 04:21.010 So let's assign these values to variables. 04:22.240 --> 04:28.720 I'm going to store the returns in value in the unwearable and I'm going to store their returned at our 04:28.720 --> 04:30.070 value in the area. 04:30.640 --> 04:31.060 OK. 04:32.010 --> 04:35.450 All right, that the print the return integer value as well. 04:36.700 --> 04:38.770 Print unconverted number. 04:40.700 --> 04:46.760 I'm going to pass variable here, OK, then let's bring to return to their value terms. 04:47.970 --> 04:48.450 Error. 04:50.850 --> 04:59.250 I'm going to pass er, as you can see, I can't print and our value because Engo errors are just values. 04:59.970 --> 05:01.380 OK, this is important. 05:02.540 --> 05:08.570 If something is a value, then you can use it almost in everywhere because it's just a value. 05:09.440 --> 05:10.700 OK, now Lipman's. 05:11.780 --> 05:16.010 First, I'm going to pass the correct number 42 like this. 05:17.150 --> 05:19.460 Notice that it has returned near here. 05:19.970 --> 05:22.290 Remember, this is the returned value. 05:22.880 --> 05:23.930 So now it's nil. 05:23.960 --> 05:26.690 So this means that the function has been successful. 05:27.390 --> 05:29.510 As you can see it prints for it to here. 05:30.840 --> 05:32.860 So the conversion was successful. 05:33.660 --> 05:39.630 Remember, a Twohy function can only convert a street value, which contains a correct numeric value. 05:40.350 --> 05:44.250 So now I'm going to run it with a non numeric value so it will fail. 05:48.190 --> 05:52.210 Look at the distance, it has returned to zero here because it has failed. 05:52.810 --> 05:59.500 As I said, you should never use the return value from a failing function and it has returned that value. 06:00.370 --> 06:04.400 As you can see, our values can present themselves here. 06:04.450 --> 06:06.470 The Arab world prints itself like this. 06:07.180 --> 06:11.910 So in summary, when a function returns an error of value, you should always handle it. 06:12.550 --> 06:18.370 And when there is an error, you should never use the rest of its results values except the error value. 06:19.240 --> 06:19.650 All right. 06:20.170 --> 06:20.940 That's all for now. 06:21.910 --> 06:27.220 Congrats now you know what, and everybody's in the next picture, I'm going to show you how to handle 06:27.220 --> 06:28.690 the returned Arabella's. 06:29.560 --> 06:30.190 See you there.