1 00:00:00,009 --> 00:00:01,018 Welcome back. 2 00:00:01,029 --> 00:00:01,769 So in the previous video, 3 00:00:01,779 --> 00:00:04,869 we talked about handling errors and also the 4 00:00:04,880 --> 00:00:09,880 different types of specific except file related errors 5 00:00:10,039 --> 00:00:12,270 that we should be working with. 6 00:00:12,619 --> 00:00:13,670 However, 7 00:00:14,079 --> 00:00:20,100 what if we wanted to check for multiple types of errors? 8 00:00:20,799 --> 00:00:24,739 Maybe in addition to the file, not be not been found. 9 00:00:25,079 --> 00:00:28,180 It's possible that the file was found, 10 00:00:28,590 --> 00:00:33,119 but then maybe the permissions for the file are not correct 11 00:00:33,319 --> 00:00:37,180 or maybe the directory wasn't correct, you know, something like that, right? 12 00:00:37,189 --> 00:00:39,990 So we want to create a program, a block of code 13 00:00:40,229 --> 00:00:43,450 that can handle multiple types of errors 14 00:00:43,580 --> 00:00:48,180 and also print out different error messages for each error 15 00:00:48,840 --> 00:00:52,250 as it is right now, I have one error which is the file, 16 00:00:52,259 --> 00:00:56,409 not found error and it's gonna print a file, not found. 17 00:00:56,840 --> 00:00:59,500 But what if I were to include 18 00:00:59,990 --> 00:01:02,689 the permission error as well? 19 00:01:03,200 --> 00:01:04,970 It's very, very straightforward. 20 00:01:04,980 --> 00:01:10,010 All I would need to do is just simply open up another block and then just say accept 21 00:01:10,970 --> 00:01:12,279 and then permission 22 00:01:12,480 --> 00:01:12,879 error 23 00:01:14,069 --> 00:01:15,029 at my colon. 24 00:01:15,300 --> 00:01:16,919 And now I can print 25 00:01:17,349 --> 00:01:18,389 in brackets 26 00:01:18,900 --> 00:01:19,800 and then say 27 00:01:20,080 --> 00:01:21,040 sorry, 28 00:01:21,510 --> 00:01:24,599 you do not have the permission 29 00:01:26,690 --> 00:01:29,510 to access this file. 30 00:01:29,900 --> 00:01:31,190 And that's all I got to do, 31 00:01:31,519 --> 00:01:35,790 let's add one more error. So I can say accept 32 00:01:36,540 --> 00:01:37,400 and then 33 00:01:37,629 --> 00:01:38,639 I can say 34 00:01:38,989 --> 00:01:40,430 OS 35 00:01:40,650 --> 00:01:40,970 arrow, 36 00:01:41,470 --> 00:01:44,279 OK. Maybe there was a problem with the operating system 37 00:01:44,489 --> 00:01:45,989 and then again my colon 38 00:01:46,290 --> 00:01:48,519 and then I can say print 39 00:01:49,330 --> 00:01:50,629 and then in brackets, 40 00:01:51,980 --> 00:01:55,139 there is an OS 41 00:01:56,860 --> 00:01:57,360 OK? 42 00:01:58,150 --> 00:02:01,730 And now what if I wanted to add one more block of 43 00:02:01,739 --> 00:02:05,730 code that will handle any other potential type of error out there? 44 00:02:06,160 --> 00:02:07,330 All I would need to do 45 00:02:08,000 --> 00:02:09,820 is to again say accept. 46 00:02:10,639 --> 00:02:11,580 And now 47 00:02:12,619 --> 00:02:15,000 the key was I'm going to say Exception 48 00:02:17,550 --> 00:02:18,339 as 49 00:02:18,470 --> 00:02:19,009 E. 50 00:02:20,399 --> 00:02:23,080 So basically this line will handle any other 51 00:02:23,089 --> 00:02:25,880 type of error that could potentially occur. 52 00:02:26,220 --> 00:02:29,830 And then I'll just simply say, put out a general message and say print 53 00:02:30,330 --> 00:02:31,860 and then I'll just say, and 54 00:02:33,179 --> 00:02:34,710 unexpected 55 00:02:37,610 --> 00:02:39,830 error has occurred. 56 00:02:41,600 --> 00:02:46,369 And now we want to stress the E here, this is going to represent the arrow. 57 00:02:46,589 --> 00:02:50,020 So what I'm going to do right now is I'm going to use our F string as usual 58 00:02:51,229 --> 00:02:51,970 and then 59 00:02:52,979 --> 00:02:57,389 curly braces, I'm going to add the E right there. 60 00:02:57,600 --> 00:03:01,059 So the last line in here will handle any other type of error. 61 00:03:01,270 --> 00:03:01,850 And 62 00:03:01,970 --> 00:03:03,330 the system would say 63 00:03:03,440 --> 00:03:08,199 an unexpected error has occurred and then it will specify what type of error 64 00:03:08,360 --> 00:03:13,740 because of the E variable in here that we created over here. And 65 00:03:13,960 --> 00:03:17,740 that's it. I'm going to run my program and of course, you can see 66 00:03:18,050 --> 00:03:19,479 it's gonna work perfectly fine 67 00:03:19,789 --> 00:03:21,100 and this is how 68 00:03:21,259 --> 00:03:24,509 you can create multiple except blocks 69 00:03:24,720 --> 00:03:30,210 that will handle multiple different types of potential errors that might occur. 70 00:03:30,220 --> 00:03:32,289 Thank you for watching. I will see you in the next class.