By exceptionally dry, except and finally.
Python has many built-In exceptions, which enables our program to output an error message when something
is going wrong.
So there are different mechanisms to help of such error.
Messages can be generated whenever there is some error in the system.
So when those exceptions occur, it causes the current process to stop and passes it to the calling
process.
And until it is handled, so if not handled, our program will crash.
So for the better understanding on this concept, let us go for one practical example and to show you
that how this trial except and finally are working now in this demonstration, we shall discuss more
on these exceptions and errors in Python.
So here to see here, we have having one tribe block.
It is equal to 100, basically to twenty six to a baby B so here we are having one except block.
That is the digital division error.
So except on this JIRU division hatred and division, Brazil is not possible.
But here to see the beat is having the value which is Longido.
So we are expecting that this particular division, Giru Division error will not be raised.
So let us go for the execution.
You can find that this particular code has got not printed, so let us print it.
So now if I go on executing, we can find that there's 100 by 26 to 5.0, so it is giving output because
there is no error has occurred.
But if I make this one, if I make this one as a zero, then obviously that division by zero is not
possible that the control is coming directly from this particular line to this except block.
And this particular statement is getting printed, which is written under the except Gedo deletion error
block.
So now you can find at that point about one exception is orcharding.
Then from that line, the control is coming directly to the respective except block, and that is part
of the code in the trade block will remain unreachable and aren't executed.
So let us suppose I'm just writing this one in this way.
OK, now if I go for the execution, I'm writing this one is 100, writing this one is 20, I'm getting
dirty.
Great output as well.
So now if I go for the execution, you can find that I'm giving the ABC and giving the value.
You see, when I'm writing this value ABC, I've given the ABC it cannot be converted to the to the
indigent using the type conversion method.
That is a..
So what is the error here?
It is evaluated.
So that's why I can also go for the value error here.
So now I can raise here.
So I'm writing one except.
The detectives are not proper, so I've given this evaluator here, so now if I execute my code and
if I get 100 and then ABC, you can see I'm getting the this particular statement got printed.
That is the data types are not proper.
So if I execute and if I put ABC at the first, then also it is this particular evaluator will be caught
here.
So you see, whenever you are performing this conversion to integer and whenever I'm giving the input
string as ABC, ABC cannot be converted to integer.
So that's where the data types are not proper.
This particular statement is getting printed because the content is coming directly to this except valuated.
So it is not going for this JIRU division either, because that exception, that error is not happening.
So let us go for another one.
I'm going for the I want to have one restriction on this eight.
So I'm just writing this one if it's.
If it is below this zero.
That means if it is negative, then I shall have one.
Raise say I'm going for the animators, a typedef.
OK, so I'm just writing this one race type error, so here.
OK, so now what will happen, see?
And putting the value one hundred and twenty, it is giving me the outcome.
I'm giving the value minus 90 and giving the value says 16, I'm getting the output output that the
data is not in range.
So in this way, also, we can raise your type here.
Here.
So now I'm doing another check.
I'm just going for X, Y, Y, you see X and Y, they are not defined here.
Then what will happen if I go on executing it is asking for the value.
So let me give the values.
And now it is raising one error that is animated, it is raising money.
That is the X is not defined.
So that that means I should go for I should go for another one.
There is a limited.
So data items are not defined, so that is my respected Blocher Britain print data items are not defined.
So now if I go on executing so these values and providing no issues, but it is producing the it is
the is coming to this except limited and this particular statement is getting printed that the data
items are not defined.
So in this way, in this particular demonstration, you can find that one trade block can be followed
by multiple exit blocks.
And depending upon the result, depending upon the error type, which will be raised within the trade
block, accordingly, the respective exit block will be executed and this part of the trade block will
remain unreachable and unexpected.
Thanks for watching this video.