WEBVTT 00:01.050 --> 00:05.920 Not let us leave everything aside and just focus on our exception handling. 00:06.210 --> 00:13.130 So I'm taking a simple example in which I'm digging or dessert as none and then I'm taking input from 00:13.130 --> 00:15.800 users and converting them into him. 00:15.950 --> 00:22.740 After that I'm calculating their division and putting that into my reason and just printing out my design. 00:22.920 --> 00:24.190 Discord looks fine. 00:24.200 --> 00:25.710 Let me run this one. 00:26.000 --> 00:28.550 The first number that I'm willing to give is 50. 00:28.580 --> 00:30.080 And the second one is 10. 00:30.080 --> 00:36.850 You can see I was able to achieve my desire include lootings look with what I tried to get 15 0. 00:36.890 --> 00:42.170 Then I must be getting a zero division later like I was getting in my domino. 00:42.500 --> 00:45.480 So this was the error that I was getting in my 0. 00:45.560 --> 00:47.440 I got zero division. 00:47.690 --> 00:57.190 So let me try this one here I get 50 and then I get zero and I got zero division error that is divided 00:57.190 --> 00:58.060 by zero. 00:58.240 --> 01:05.860 As soon as we try to run this game on our first few lines are executed and as soon as I then enter my 01:05.860 --> 01:07.420 program stops. 01:07.430 --> 01:10.510 So I got an error on line number five. 01:10.570 --> 01:17.020 And after that my program stopped and all the lines after that have been executed because we haven't 01:17.020 --> 01:18.650 handled this exception. 01:18.700 --> 01:24.470 So we got it and we got an exception and we are not handling that error. 01:24.490 --> 01:26.550 So quite an unusually big sound. 01:26.680 --> 01:32.660 So even if I tried to pin something here and run this one again 01:35.660 --> 01:38.870 you can see I still got error on my number five. 01:38.870 --> 01:42.580 And after that I was not able to print my line number six. 01:42.590 --> 01:47.820 That means I don't break out because of this error because of this exception. 01:47.960 --> 01:50.410 And then we are not executing a single line. 01:50.630 --> 01:53.740 So we need to handle this particular exception. 01:53.950 --> 02:02.390 For that we use dry and except in Java in C in other different languages you might care about try catch. 02:02.510 --> 02:08.090 So in python we use try and Except never do that. 02:08.090 --> 02:14.930 Let me shift this line and on whatever line we are trying to handle that exception we just need to either 02:14.940 --> 02:15.660 a try block. 02:15.680 --> 02:19.970 That means I'm writing try and all the calls will be inside this. 02:19.970 --> 02:26.740 That means all the code which can have an exception will be inside this and then we need to add up. 02:26.770 --> 02:28.270 Except block. 02:28.580 --> 02:34.630 So that means if you are going to get any error then we are going to get inside this except block selected 02:34.730 --> 02:45.810 print a simple message and her Darco just looks at me on this one again. 02:45.970 --> 02:50.320 You can see now what I'm doing is I was trying to handle this exception. 02:50.470 --> 02:56.930 So there was an error on line number five but it haven't printed that it could inside my except block 02:57.310 --> 03:04.510 it printed this line and over that call and then it move forward with an execution without any problem. 03:04.720 --> 03:07.580 So that's how we handle an exception. 03:07.850 --> 03:15.220 Now remember as you know we have an exception class which is a base class so we can use that particular 03:15.220 --> 03:18.650 class to bring Which error we are getting. 03:18.970 --> 03:26.140 So all you have to do is you just need to define your Exec exception class or you can just define the 03:26.140 --> 03:27.950 base class of exception. 03:28.260 --> 03:32.460 You can see our intelligence is already giving us not authorization. 03:32.470 --> 03:34.950 I think most of them are about errors. 03:35.140 --> 03:43.740 So I would be using a base class and you can use ASCII or and then say does the. 03:44.350 --> 03:46.720 So now I can also print on. 03:46.750 --> 03:48.310 These are not exception. 03:48.460 --> 03:50.220 So it would be OK with this. 03:50.230 --> 03:52.540 He wanted us underscore 03:55.910 --> 03:57.770 hey can see where you got an error. 03:57.770 --> 04:00.010 This is my line error with our code. 04:00.110 --> 04:05.210 And this was the message is by our exception that is division by zero. 04:05.240 --> 04:06.880 So that's how you can handle. 04:06.890 --> 04:13.060 Now you can also print out the type of this or let me remove this one and print out the type of font 04:13.070 --> 04:13.820 enter. 04:13.850 --> 04:17.810 So all you have to do is use type and we just need to parse out the 04:23.520 --> 04:26.940 hey you can say I got my zero division and or pay. 04:27.100 --> 04:34.600 So that means at this point of time I'm getting this particular error because of this class now for 04:34.680 --> 04:39.170 trying to get different input maybe some string. 04:39.300 --> 04:45.740 Now let me move this one because I just wonder if we are already converting them to India and to not 04:45.840 --> 04:50.820 import and taking as indeed a flawed string and then try to run this one. 04:50.820 --> 04:56.480 And what if I give a string and divided by a number I might get an error. 04:56.480 --> 04:58.030 Let us do that also. 05:00.400 --> 05:04.090 Let me give a 50 and then give a string. 05:04.210 --> 05:06.330 You can see I've got a type error. 05:06.340 --> 05:13.110 So in the previous example I was getting zero deviation error and here I'm getting type error so big 05:13.110 --> 05:18.290 and mean Towcester does with the odd mean base class we get handed all the exception. 05:18.420 --> 05:22.350 But what if I just want to handle one particular error. 05:22.420 --> 05:24.950 Maybe I just want to handle this type better. 05:25.120 --> 05:27.470 Feigin you just type it as. 05:27.520 --> 05:29.100 And then I can print that. 05:29.330 --> 05:37.310 So I can directly use my type instead of my base class and I don't use that and without any error you 05:37.310 --> 05:37.690 can see. 05:37.680 --> 05:39.670 Now I'm inside my Deibert. 05:39.710 --> 05:44.210 But what if I get now 50 zero that has zero to be in error. 05:44.240 --> 05:44.980 Let me see more. 05:44.980 --> 05:45.860 I'm going to have 05:49.420 --> 05:51.560 and I'm still getting by for you. 05:51.610 --> 05:52.200 Why. 05:52.240 --> 05:55.340 Because you are taking board as string. 05:55.480 --> 05:58.760 So you have to take it out disputing your example also. 05:58.960 --> 06:00.760 So let me just add my entire 06:05.330 --> 06:10.560 not just look trying that means no I'm not going to handle the state better yet. 06:10.560 --> 06:15.150 I was just dividing my 50 as string and it was a string. 06:15.150 --> 06:16.880 Now let me clear this up. 06:18.700 --> 06:24.770 Now you can see I'm not handling my zero division error because I'm just handling my pipe. 06:25.100 --> 06:29.740 So this division error is actually breaking my exception. 06:30.160 --> 06:35.520 So what I can do is I can also add or except block for my 0 division. 06:40.940 --> 06:45.820 Let me clear this up and this one gets 50 and 0. 06:45.820 --> 06:49.070 Now you can see I'm inside my 0 to be in error. 06:49.210 --> 06:51.340 And then my line and then my own. 06:51.550 --> 06:55.720 So that's how we can handle different of error specifically. 06:55.810 --> 07:01.600 So you might have some different method for type error you might have some different called for 0 division 07:01.660 --> 07:02.310 error. 07:02.380 --> 07:09.290 If you have everything same then you can remove everything and then you can use base class that is exception. 07:09.640 --> 07:11.690 And hey you can give specific error. 07:11.800 --> 07:18.340 I hope not understand about how to handle exception use of trialogue and music except block by block 07:18.370 --> 07:25.530 on the code from which we can expect errors except block is to code to handle the exception. 07:25.780 --> 07:32.530 Now the second thing is we can use an exception class that is our base class to define exceptions. 07:32.540 --> 07:39.750 We can also use specific exception classes like type like 0 division either and and on all different. 07:39.910 --> 07:44.570 So we can use except multiple times to define a different type of error. 07:44.740 --> 07:50.500 If you have any doubt that why we're using different exit blocks think of all as a web site then you 07:50.500 --> 07:51.760 have four or whatever. 07:51.790 --> 07:53.490 That is not fun. 07:53.550 --> 07:57.450 We took some different data then we have 500 error that is. 07:57.460 --> 07:58.680 So we're not alone. 07:58.770 --> 08:00.640 We tools on different page are different. 08:00.670 --> 08:07.330 And then we have something like 300 That is some different data and then we have 200 something like 08:07.330 --> 08:07.620 that. 08:07.630 --> 08:10.380 Our server called that means all OK. 08:10.390 --> 08:12.220 So that's how we divide those. 08:12.220 --> 08:17.160 And this was really important for you to understand how to handle different patterns. 08:17.350 --> 08:21.400 So that's all for this little mix we are going to talk about. 08:21.570 --> 08:21.930 Right. 08:21.970 --> 08:22.980 Except is. 08:22.980 --> 08:24.680 And finally so see. 08:24.730 --> 08:25.630 And the next one.