In this video, we are discussing user defined exceptions with one demonstration.
So here is the demonstration for you.
So in this session, we are discussing user defined exceptions where defined one class, the name of
the class is voter's eligibility, which is inheriting the class exception.
And these voters eligibility class is having one method that is a constructor to have defined.
And from the constructor, we have called the best class constructor that is using the method support
he had.
The best class is the one exception.
So voter's eligibility is one.
It was a different class, which is inheriting the best class.
That is our exception.
And these voters eligibility is having one constructor from the constructor.
We have called the super method to call the best class constructor.
So now let us come to the to the other part of the program.
Call within the tribe block.
Each has been initialized with 12 and if it is less than a pin, then raise voter's eligibility.
So here we are using that use a different exception.
So that's why we're manually raising the exception, that is a voter's eligibility to handle the situation.
We having the exit block, that is the exact voter's eligibility, which is printing the age is less
than 18 here.
And when this particular exception will not be raised, then the content will come back to the else
block.
And here age is greater than or equal to 18.
This particular code will get excluded.
So now let us go for the execution, for the better understanding.
You see, the age is less than 18 is getting printed.
So that means that age is 12.
So 12 is less than 18.
The condition is true.
So this voter's eligibility will be raised and then the candidate will come back to this voter's eligibility.
So age is less than 18 is getting printed.
So now let us go for inclusion of the final here.
So let us go for the final.
So we're hitting this one end of the program, you can find that the final block is getting executed.
So which blocks are getting executed at first try as the age is below 18.
So the exit block is block is not getting its control for the execution and then the final block is
getting executed here.
So now let us go for some modifications here that are making this one C21.
So let's let us see what will happen.
So here we are having this 21.
So except so the Rays voter's eligibility will not be executed.
The exception will not be raised.
So contant will come to the else block.
So Agee's get that they're not equal to 18.
That message has got printed, that string has got printed and final block is getting printed irrespective
of the fact, without any exception has occurred or not.
So here we are printing the age.
He had a print in this age, you can find that the ages 21, it is greater than or equal to 18 else.
Block has got a scandal for execution end up the program to finally block has got its content if it
make this one 12.
Then ages 12.
So this particular trade block has got to control from here.
This condition is true.
So the voter's eligibility will be raised.
Will come to the exit block.
So age is less than 18 has got printed.
That else block will be skipped.
The final block will get the control end up.
The program is getting executed.
So now let us suppose I'm just putting this to within double quotes.
So it has become a string.
So here to see one error has occurred, there is a typo in it, so I should have the respect to block
prototype better.
So age is not numeric, so that is a typo.
You can find that ages 12, so the trade block has got its control and got execution.
Now, you see here we are performing this check.
That means age is less than 18.
So age is a string.
So this comparison cannot be done.
So age is not numeric.
So the respective TYPEDEF will be raised automatically.
We're not raising when this comparison will be done, then the system will be raising this type error.
So control will come to this except riperton and age is not numeric.
That particular string is getting printed and then the final block is getting printed, is getting executed
and the statement is getting printed.
So you are getting this idea how this user defined exceptions can be written in about Biton.
Thanks for watching this video.