Python Jumpstart by Building 10 Apps Transcripts
Chapter: App 10: Movie Search App
Lecture: Concept: try except

Login or purchase this course to watch this video and the rest of the course contents.
0:01 Let's close out application ten by looking at this concept of try except blocks.
0:06 Here you can see we have a couple of methods that we are going to call, method one, two and three, and they may call other methods,
0:11 and those methods call other methods, down deep into the Python standard library and maybe in one of them way down there there is a possibility
0:18 that one throws a connection error. Kind of like we saw with our request method calls, when the network was down.
0:23 Now, it doesn't matter how deep down the chain you are or anything like that, if there is an exception and it is not handled,
0:29 then it's going to be raised and it will fly up here, it will immediately start making its way, if let's say method two has the exception,
0:37 so it will start run method one, successfully, method two will run until it hits the exception- done,
0:41 it will skip method three it goes straight to here. Now test, is the error a connection error, does it derive from or is it exactly this class,
0:48 if that is true then we'll be int his exception block. If that's not true, it will keep going down the list.
0:53 Now the order here matters a lot if you say exception at top and then connection error at the bottom
0:59 because it just stops and the first one it hits their matches, it said you are done for it, it will actually never ever process the connection error
1:06 if you have a more base error or a more generic general error handling block at the top, super important to go from most specific
1:13 to least specific as you go through this.


Talk Python's Mastodon Michael Kennedy's Mastodon