Hi there.
I think it's a good time to try to resolve these three meaning assignments, so let's do it.
Basically, what I'm going to do now is just copy all of these three parts, open bicarb and go to piece
them right here.
And basically we have three separate assignments.
So first of all, let me just write a comment here, which is exceptions.
There's practice and also here just going to change the name of the file to.
Exceptions, heroes practice.
Like that.
All right, so just going to do to market and do control, backslash and also control backslash to that
part and we're just going to try to resolve the first one.
OK, so this is the code that we have.
If we write as is, we're going to have an exception.
All right.
So we having a casting exception, which we are very much familiar with, and we're going to put all
this code inside.
Try.
Like that, and then we're going to use except to basically resolve this issue and we're going to right
here to the end user, that casting was not.
Made for the.
For the president of X.
OK, and right now we're going to do print.
The number is and then we're going to put percentages and then percentage X.
Like that, yeah, but we're having an additional issue here, I think that X is not recognized, it's
undefined.
All right, because we define the X in the try.
We cannot use it inside the except.
So we have two options, OK, because the accepters not familiar with what happens inside the tri.
So we have two two options.
We either can declare it again inside the ship, which is a worst, uh, solution.
But the better solution is just to define it, defined it outside of try and accept.
And that way they both are going to have access to it like that.
All right.
Um, let's run it now.
All right, there you go.
So you have this X defined outside the tri accept statement, then we had a failure.
So the code immediately went to accept and you can see casting was not made for print of X, the number
is five, OK?
And I also want to show you that whatever comes after the except for example, we have print ABC here
will also run.
All right.
So you can see ABC also is being run, even though it's outside the except because everything comes
after the acceptable run perfectly.
All right.
So that was our assignment.
Simon one, and we have completed it.
All right, now we're going to handle with assignment to let's also put here print special key keyword
and solve the printouts right here would be divided with spaces.
So we have this statement of X basically that let's make it a Y, OK, because X is defined for us and
we're basically trying to resolve it in the same file.
So if printing making X plus five, nothing will go wrong because we already have X here, but it's
in a different assignment.
OK, they are separate assignments.
So we have this Y plus five and once we run it, we're having an exception.
Name Y is not defined OK, because we did not define Y and we also are going to put it in so dry with
intention right here and then except going to have y was not defined.
Name error was raised.
And now we're going to also defined why as well as we did before, y equals to one doesn't matter.
Yeah.
And now we can do Y plus five and then print Y plus five.
Yeah.
So what do you have here, stateman have no effect.
Oh, yeah, no problem.
Let's do, for example, result.
Like that, yeah, as long as we're not raised, with an exception with why plus five, this is the
meaning of the assignment to avoid the exception.
So no number is five.
We have but this printout we do not have.
And why is that?
Let's try to investigate.
Oh, so obviously, huh, I see what happened here, obviously, if I declared why outside the scope
of dry except so now we do not have an exception inside dry.
OK, this line does not cause an exception which is going to prove it to you.
We're going to put Brent A.B.C. here so we're not having any exception in here.
Yeah, you can see ABC because we have declaration of way, so we basically aborted the mission.
So we're going to remove the Y equals one here because we do want to have an exception inside the tray
and we do want it to go inside the except.
So we're going to put Y equals one right here like that.
Oops, wrong button.
Yeah, so now we are getting what we wanted, why was not defined name or was was raised and then we're
printing of one of Y plus five and we're getting the result right here.
So this one also was handled.
And now we're going to do this one assignment to now we're going to resolve assignment number three,
which is this one.
Let's remove the last note.
Right.
And we're going to try and here.
Right.
And except and this what's going to raise an error right here is unexpected.
EDF, what is it?
We don't have anything here.
OK, so now we're not having we having an error here, you can see that cold is not going to reach.
Code is not going to reach, but this line right here.
All right, because it fails over here, OK, fails over here and you can see it in your own eyes.
Let me just I'm just doing some experiments intentionally so you can see all the behaviors.
Yeah.
Yeah, there you go.
So we having several errors here.
First one is here, but that actually is not relevant.
It shows us the reason is it shows us all the exceptions that happened because we're having one exception
here and it basically shows us all the exception that happen.
But if we divide it into three files, OK, let's do a practice exception.
Practice one.
And then we're going to break exception practice to.
And I'm going to have exception brought these three, we're going to divide these three examples into
three, we would not get this error.
OK, so we're going to put this assignment three in file three and we have assignment two.
We're going to leave here an assignment one we're going to put in here.
OK, so you see what I did here?
I said each assignment of its own file and we're going to run the first one, OK?
We're perfectly going to run the second one, which we already did
up.
Run also runs perfectly, and only this one will fail once you run it and you can see indention error
first if we remove the indention.
We also are going to have index error because we were having index six here while having only index
three, last one in the list.
So this one we're going to also put inside try and right here we're going to set list.
You know what?
Let's take the list.
Put it outside.
Yeah, this is the most effective way instead of declaring it once and once and except it right here,
we're going to do a print list three, OK, three, which is the last one, the last index inside of
the list.
And we're going also to write.
Tried to.
Pool index six, while only three are valuable.
Yeah, and now if we run it, you can see the the run of the cold went into accept and basically ignored
this sprint x x because we had an exception right here.
And you can see that no error happened in the execution.
Everything's OK.
The code is keeping its execution.
Even though we have an error here because we wrapped it, we're dry accept and it went straight over
to the airport.
All right.
So this concludes are the exception and our handling as well.
I will see you in the next video.
Thank you.