 Today, we're going to be talking about exception handling the entire way I want you to think about exception handling is let's just imagine for a second This is your program. Okay. It's the it's the world. It's going nicely It's going smoothly nothing wrong with it going on there and then your program crashes Well, what happens typically if you think about when your program crashes? Everything's on fire. You're freaking out, you know, oh crap, you know, I'm late for my submissions all that nonsense You know Typically, you know, the idea is that when your program crashes It halts entirely and the entire reason why is because it does not know what to do You didn't tell it what to do in this situation So just as a a nice little example of this Let's say for example, I came in and said x equals 10 simple enough nothing crazy And then I came in with y equals zero print x Divided by y Now if you were you know astute you realize we can't divide by zero. That's mathematically impossible We should not be allowed to do that Python allows me to do it now Python Doesn't know what to do in the case of a divide by zero. It's freaking out over this. So it's gonna crash Now as programmers were pretty smart about this, you know, we wouldn't do something like this But we might have to deal with something where the user Types in things that can cause us to crash So say for example, I come in enter a number and I'm just gonna copy that into my y Same kind of thing. Oh, well now it's not me the developer who's writing out these zero Divisions, it's the user who comes in and crashes me and the same kind of thing Well, maybe the user's smart enough. Maybe we do some air handling and we can you know Input validates what they're typing and so maybe oh, okay Maybe okay, they they do the 10 instead of not typing zeros because we stop that they type in a That's a completely different error entirely. So what we can do is inside of our programs You know, yes We can do some if statements and while loops to make sure we're validating their inputs beforehand But sometimes it gets through and so what I also like to use is something known as the try Now the try the entire idea I like to imagine is it's treating this like this code that I'm tabbing in right now All of the code in here doesn't automatically happen. I like to imagine it's a parallel universe, right? We're using the globe A analogy that I showed in the slides. I'm gonna create a Parallel universe to my own where this code happens and Let me just see what happens Okay, well what happens if it works fine perfect that means I'm allowed to do it myself if it doesn't it crashes Oh, well We have stuff to handle that for a second and that's where the except comes in the play Except is basically saying oh well here now. I want to stop something from happening. So print You cannot divide by zero but And so again now I run this boom Enter a number I enter my 10 now again like I said if the code works perfectly fine again I'm watching it and I say that's perfectly fine run that For myself in this case five divided by ten divided by five Parallel universe sees that goes okay. That's perfectly fine. I'll allow it and I print out oh 2.0 Now if I come in and do my 10 divided by zero Instead of me erroring my program Allows me instead of doing this. I'm sorry instead of doing which one are you there instead of doing this error It catches it and fixes it you cannot divide by zero and the reason why we want to do this is because I might have print Other code that needs to run Now if I again if I come in and remove those try accepts Boom run this into the number 10 zero I never get that other code needs to run the program halts entirely the try catch or try Accept block is going to now take that I say my 10. I say my zero You cannot divide by zero other code that needs to still run So that code actually will activate it will still do its thing now with that Think we're pretty good