Welcome back.
In this lecture, I'm going to show you how to handle the errors with examples.
If you're coming to go from other languages, you may be surprised that God doesn't have to catch statements
or exceptions in the usual sense, as I showed you in the last lecture.
We go first, use a simple if statement to check for the errors explicitly because it's more readable
and bugs cannot hide under the buggy code or inside a troll cat statement.
Let's check it out now.
Engo Some functions always work without any errors.
For example, let's take a look at the ETA app function from the Starcom package.
You've seen it before.
It just takes an intaglio and an argument and converts it to a string rather than returns it.
OK, this function always succeeds and it never fails.
It's because an integer can always be converted to a string value no matter what.
There is no need to return an error from this function.
So since this function return error values, so you don't need to handle any errors when you call it.
OK, now let's take a look at an example, got to understand this better.
Let me call this the article that I took by passing it an integer value like this.
Forty two.
OK, I'm going to say the result of this function into the swayable, which is a shrink, since it's
our function, returns a string.
Let's take a look at the documentation of this function again to better understand how it works.
As I showed you before, it takes any value as an argument.
And this is incredible.
OK, it's that simple.
All right.
Let's bring the result now.
OK, renters are.
As you can see, just prince it to as a swink, nothing interesting here so far, but now you've seen
that you don't need to handle any errors for this function because it doesn't provide an error value
for you to check.
It always succeeds.
Now, let's take a look at another function which returns an error value.
Here is another function from a Starcom package.
A to I means as key to integer, you can think of ASCII as a string value, so it takes a string value
and it tries to convert it into an hourly pay attention to my work.
Now it tries so it doesn't always succeed.
As you can see here, that's why it also returns an air value, that error, rather, tells us about
whether the conversion from the street value to int value is successful or not.
As I said, this function doesn't always return a successful result.
It may fail, and when it does so, you should never use the return value from this function because
the returned value may be in an undefined state.
It's probably going to be a value which you didn't expect.
But in the case of a two hour function, it returns zero as an error.
So it doesn't matter actually whether you check the air or not.
I'm just showing it to you here as an example for handling errors.
It's just a simple example.
OK, now let's take a look at its value.
When it returns a new air value, it means that the function is successful so you can use the converted
into value.
OK, otherwise when it returns a nominal at our value, it means that the conversion has been failed
and it couldn't convert the past value to an integer.
Let me show you this function in the coding, Ed, as an example so you can understand it better.
Let's first call the A to our function like this.
And let's pass it a command line arguments.
As you can see here, it returns on its value and an NRL rights.
So let's assign these values to variables.
I'm going to store the returns in value in the unwearable and I'm going to store their returned at our
value in the area.
OK.
All right, that the print the return integer value as well.
Print unconverted number.
I'm going to pass variable here, OK, then let's bring to return to their value terms.
Error.
I'm going to pass er, as you can see, I can't print and our value because Engo errors are just values.
OK, this is important.
If something is a value, then you can use it almost in everywhere because it's just a value.
OK, now Lipman's.
First, I'm going to pass the correct number 42 like this.
Notice that it has returned near here.
Remember, this is the returned value.
So now it's nil.
So this means that the function has been successful.
As you can see it prints for it to here.
So the conversion was successful.
Remember, a Twohy function can only convert a street value, which contains a correct numeric value.
So now I'm going to run it with a non numeric value so it will fail.
Look at the distance, it has returned to zero here because it has failed.
As I said, you should never use the return value from a failing function and it has returned that value.
As you can see, our values can present themselves here.
The Arab world prints itself like this.
So in summary, when a function returns an error of value, you should always handle it.
And when there is an error, you should never use the rest of its results values except the error value.
All right.
That's all for now.
Congrats now you know what, and everybody's in the next picture, I'm going to show you how to handle
the returned Arabella's.
See you there.