WEBVTT 1 00:00:00.140 --> 00:00:01.300 Hi and welcome back. 2 00:00:01.300 --> 00:00:02.560 In this video we're going to be adding 3 00:00:02.560 --> 00:00:05.210 a little bit of error handling to our app, 4 00:00:05.210 --> 00:00:08.293 just so we can deal with any eventualities that may happen. 5 00:00:09.210 --> 00:00:10.050 We're gonna come here 6 00:00:10.050 --> 00:00:12.093 and we're gonna surround everything in here 7 00:00:12.093 --> 00:00:15.970 by a try/except block. 8 00:00:15.970 --> 00:00:16.803 Okay. 9 00:00:16.803 --> 00:00:18.972 And the first section is gonna be 10 00:00:18.972 --> 00:00:22.710 InvalidTagforAuthorError as e 11 00:00:22.710 --> 00:00:24.990 and it's just gonna print the error message 12 00:00:24.990 --> 00:00:28.672 and then we're gonna have a more generic exception. 13 00:00:28.672 --> 00:00:30.607 And we're gonna say something like, 14 00:00:30.607 --> 00:00:33.007 "An unknown error occurred. 15 00:00:33.007 --> 00:00:34.420 "Please try again." 16 00:00:34.420 --> 00:00:36.620 So this double except, 17 00:00:36.620 --> 00:00:38.200 I'm not sure we've looked at it before, 18 00:00:38.200 --> 00:00:40.770 but what happens is if an exception is raised 19 00:00:40.770 --> 00:00:43.793 in this block here and it is an InvalidTagForAuthorError, 20 00:00:44.920 --> 00:00:46.550 then it's gonna run this. 21 00:00:46.550 --> 00:00:49.910 If it's not that, then it is gonna run this 22 00:00:49.910 --> 00:00:52.950 because Exception is the base class for every exception. 23 00:00:52.950 --> 00:00:54.480 But you can have many of these 24 00:00:54.480 --> 00:00:57.600 and then they get less and less specific. 25 00:00:57.600 --> 00:01:01.020 We also do need to import our error there of course. 26 00:01:01.020 --> 00:01:06.020 So now if we run our app and we say we want Bob Marley 27 00:01:06.030 --> 00:01:08.833 and then we want something like magic. 28 00:01:09.711 --> 00:01:11.610 What you'll get is Chrome will launch, 29 00:01:11.610 --> 00:01:13.230 Bob Marley will be selected 30 00:01:13.230 --> 00:01:15.887 and then you'll get your message here, 31 00:01:15.887 --> 00:01:18.450 "Author Bob Marley does not have any question" 32 00:01:18.450 --> 00:01:19.690 Any question? 33 00:01:19.690 --> 00:01:20.540 Why question? 34 00:01:20.540 --> 00:01:22.340 I'm not sure why I typed question there. 35 00:01:22.340 --> 00:01:24.630 Does not have any quotes. 36 00:01:24.630 --> 00:01:26.820 I'm not sure why I decided to type question there 37 00:01:26.820 --> 00:01:28.290 but that's no problem. 38 00:01:28.290 --> 00:01:30.920 We fixed it and we've added our error handling 39 00:01:30.920 --> 00:01:32.210 there as well. 40 00:01:32.210 --> 00:01:33.190 That's it for this video. 41 00:01:33.190 --> 00:01:34.470 Thank you for joining me. 42 00:01:34.470 --> 00:01:35.920 I'll see you in the next one.