Transcript from the "try catch Error Handling" Lesson
>> So, we've been looking at the Firefox Debugger. You might be working in Chrome or Safari or another browser, different browser's Dev Tools work differently, so their debuggers work differently. So you can read up on them, there're some links in the slides here. You can read up in the documentation for your particular browser, how its developer tools work.
[00:00:18] And in fact, there is, I believe an entire course on using developer tools on front end masters. So if you think this is fun, and you're like, clicking around and poking around in the web page in your Dev Tools, you can take that course next and kind of get even more tricks up your sleeve there.
[00:00:37] But suffice it to say that the the debugger and kind of looking into what's going on inside of your functions and different parts of your code can be a useful way to figure out when something is going wrong, what is going wrong. And so then once we've figured out where something is going wrong, or maybe where it is likely, maybe we already have an idea of where it's likely that something might go wrong.
[00:03:21] So a try catch block here, which we have a try block and a catch block, they work together in order to try something that might give us an error. So for example, we have a function that we're calling here in our try block, inside our curly braces, that we think might throw an error.
[00:03:41] And try is going to try to run it, and if it works and there's no error, cool, we're just gonna go on with the rest of the code after this whole try catch block. But if this might throw an error, does throw an error, then we're going to enter the catch block.
[00:04:28] Say, as if, we can even use that code then, we write into an error and maybe we wanna do something else here. Maybe we wanna use a fallback value or we want to try some other way of getting this optional information or something like that. Or maybe we just wanna say, whatever, let's just keep going, and the catch block is going to allow us to decide what we wanna do in the event that whatever happened in the try block, throws an error.
[00:04:58] And in this case, we're just gonna log whatever and keep rolling with the homies. I hope folks that seemed clueless cuz otherwise this won't make any sense. But, [LAUGH] in any case, suffice it to say that try catch is how we can handle errors in our program and make decisions in our code about what to do if we run into an error in a particular line of code or a particular block of code.
[00:05:22] We can have more than one line in that try block two. So you can read all about try and catch on MDN, of course, and you can read a lot more about error, objects, and how that works, and what kind of things we can work with there on our error objects, and see some more examples of how to use try and catch.