1 00:00:00,680 --> 00:00:05,880 In this video, we are discussing user defined exceptions with one demonstration. 2 00:00:06,140 --> 00:00:07,670 So here is the demonstration for you. 3 00:00:08,620 --> 00:00:15,520 So in this session, we are discussing user defined exceptions where defined one class, the name of 4 00:00:15,520 --> 00:00:19,990 the class is voter's eligibility, which is inheriting the class exception. 5 00:00:20,480 --> 00:00:25,510 And these voters eligibility class is having one method that is a constructor to have defined. 6 00:00:25,780 --> 00:00:31,410 And from the constructor, we have called the best class constructor that is using the method support 7 00:00:31,690 --> 00:00:31,960 he had. 8 00:00:31,960 --> 00:00:33,790 The best class is the one exception. 9 00:00:34,120 --> 00:00:36,370 So voter's eligibility is one. 10 00:00:36,370 --> 00:00:39,280 It was a different class, which is inheriting the best class. 11 00:00:39,640 --> 00:00:40,870 That is our exception. 12 00:00:41,110 --> 00:00:44,860 And these voters eligibility is having one constructor from the constructor. 13 00:00:44,860 --> 00:00:48,220 We have called the super method to call the best class constructor. 14 00:00:48,490 --> 00:00:51,610 So now let us come to the to the other part of the program. 15 00:00:51,610 --> 00:00:53,400 Call within the tribe block. 16 00:00:53,410 --> 00:01:00,700 Each has been initialized with 12 and if it is less than a pin, then raise voter's eligibility. 17 00:01:00,730 --> 00:01:04,300 So here we are using that use a different exception. 18 00:01:04,570 --> 00:01:10,510 So that's why we're manually raising the exception, that is a voter's eligibility to handle the situation. 19 00:01:10,510 --> 00:01:16,600 We having the exit block, that is the exact voter's eligibility, which is printing the age is less 20 00:01:16,600 --> 00:01:17,550 than 18 here. 21 00:01:17,950 --> 00:01:22,710 And when this particular exception will not be raised, then the content will come back to the else 22 00:01:22,750 --> 00:01:23,140 block. 23 00:01:23,320 --> 00:01:26,030 And here age is greater than or equal to 18. 24 00:01:26,200 --> 00:01:28,640 This particular code will get excluded. 25 00:01:28,960 --> 00:01:31,990 So now let us go for the execution, for the better understanding. 26 00:01:31,990 --> 00:01:35,490 You see, the age is less than 18 is getting printed. 27 00:01:35,800 --> 00:01:37,930 So that means that age is 12. 28 00:01:37,960 --> 00:01:39,480 So 12 is less than 18. 29 00:01:39,490 --> 00:01:40,490 The condition is true. 30 00:01:40,750 --> 00:01:46,660 So this voter's eligibility will be raised and then the candidate will come back to this voter's eligibility. 31 00:01:46,810 --> 00:01:49,720 So age is less than 18 is getting printed. 32 00:01:50,260 --> 00:01:52,780 So now let us go for inclusion of the final here. 33 00:01:52,960 --> 00:01:54,340 So let us go for the final. 34 00:01:57,850 --> 00:02:03,100 So we're hitting this one end of the program, you can find that the final block is getting executed. 35 00:02:03,100 --> 00:02:08,410 So which blocks are getting executed at first try as the age is below 18. 36 00:02:08,410 --> 00:02:14,740 So the exit block is block is not getting its control for the execution and then the final block is 37 00:02:14,740 --> 00:02:15,940 getting executed here. 38 00:02:16,480 --> 00:02:21,280 So now let us go for some modifications here that are making this one C21. 39 00:02:21,280 --> 00:02:23,070 So let's let us see what will happen. 40 00:02:23,740 --> 00:02:25,450 So here we are having this 21. 41 00:02:26,020 --> 00:02:30,200 So except so the Rays voter's eligibility will not be executed. 42 00:02:30,220 --> 00:02:32,140 The exception will not be raised. 43 00:02:32,440 --> 00:02:34,420 So contant will come to the else block. 44 00:02:34,420 --> 00:02:36,660 So Agee's get that they're not equal to 18. 45 00:02:36,700 --> 00:02:42,460 That message has got printed, that string has got printed and final block is getting printed irrespective 46 00:02:42,460 --> 00:02:44,980 of the fact, without any exception has occurred or not. 47 00:02:45,520 --> 00:02:47,410 So here we are printing the age. 48 00:02:50,420 --> 00:02:56,740 He had a print in this age, you can find that the ages 21, it is greater than or equal to 18 else. 49 00:02:56,750 --> 00:03:02,780 Block has got a scandal for execution end up the program to finally block has got its content if it 50 00:03:02,780 --> 00:03:03,920 make this one 12. 51 00:03:05,240 --> 00:03:06,260 Then ages 12. 52 00:03:06,290 --> 00:03:09,360 So this particular trade block has got to control from here. 53 00:03:09,710 --> 00:03:10,960 This condition is true. 54 00:03:10,970 --> 00:03:13,430 So the voter's eligibility will be raised. 55 00:03:14,180 --> 00:03:16,070 Will come to the exit block. 56 00:03:16,080 --> 00:03:18,410 So age is less than 18 has got printed. 57 00:03:18,860 --> 00:03:20,450 That else block will be skipped. 58 00:03:20,450 --> 00:03:22,810 The final block will get the control end up. 59 00:03:22,820 --> 00:03:24,570 The program is getting executed. 60 00:03:25,040 --> 00:03:28,640 So now let us suppose I'm just putting this to within double quotes. 61 00:03:28,640 --> 00:03:29,900 So it has become a string. 62 00:03:31,370 --> 00:03:36,470 So here to see one error has occurred, there is a typo in it, so I should have the respect to block 63 00:03:36,470 --> 00:03:37,270 prototype better. 64 00:03:42,220 --> 00:03:44,550 So age is not numeric, so that is a typo. 65 00:03:44,770 --> 00:03:50,880 You can find that ages 12, so the trade block has got its control and got execution. 66 00:03:50,940 --> 00:03:53,580 Now, you see here we are performing this check. 67 00:03:54,310 --> 00:03:56,860 That means age is less than 18. 68 00:03:56,860 --> 00:03:58,210 So age is a string. 69 00:03:58,210 --> 00:03:59,970 So this comparison cannot be done. 70 00:04:00,580 --> 00:04:02,430 So age is not numeric. 71 00:04:02,440 --> 00:04:05,670 So the respective TYPEDEF will be raised automatically. 72 00:04:06,040 --> 00:04:10,860 We're not raising when this comparison will be done, then the system will be raising this type error. 73 00:04:11,200 --> 00:04:15,060 So control will come to this except riperton and age is not numeric. 74 00:04:15,070 --> 00:04:20,590 That particular string is getting printed and then the final block is getting printed, is getting executed 75 00:04:20,590 --> 00:04:22,000 and the statement is getting printed. 76 00:04:22,450 --> 00:04:27,430 So you are getting this idea how this user defined exceptions can be written in about Biton. 77 00:04:27,910 --> 00:04:29,170 Thanks for watching this video.