Guys, in today's video we'll see what error objects are. How do error objects work? And how can you throw a custom error? For example, if the user puts in the wrong information, then I want to throw a custom error to the user. How is this done in JavaScript? Let's go to our computer screen and get started... So, guys, let's learn about error objects. As a result, I'd like to create a new repl. I'll simply make a new repl and that will Wait a minute... I'll go to my profile and then, We'll talk about error objects. Now if you don't know what they are, so the "err" from our last session is the error object, about which we'll talk in detail today. This is our video no. 61, so I'll type "61_error_object". Let's create a repl and move to our notes. "For all the built in errors, the error object has 2 main properties" Error object has 2 properties for built in errors. What are they? "name" and "message" are the two properties. We rarely see stack, but these 2 are the main properties. So let's produce an error and then we'll see how we can use try catch error. So I'll take try catch error and in try I'll type "Harry", which is a variable and is not defined,so it's obvious that we'll see an error. And we want to see that error so that, we understand these things. So please focus here I'll type console.log So I just typed harry here. and it prints "harry is not defined". This whole error prints here. But if I write error.message, then see how this changes. Rather than doing this, I'll put in error.name and error.message and run them. So I'll type error.name and I'll type error.message. So name done, message done; Let me reload so that you can see what name is Name is a reference error. And this "harry is not defined" is the message. So we can use this error's name and message to indicate or identify or to take a set of actions when a reference error occurs. Do this if you get a syntax error, or do this for something else. Now let's say I want to throw custom errors here. I'll only tell you how to throw custom errors. If you want to throw custom errors and you type "throw new error" and then you type "Harry is not good" and throw this error here; and reload it. So you'll see this is an error and "harry is no" which is also an error. Now if I type throw new reference error. Then you'll get "type of error: reference error". Let me reload this properly. Let's save this. If I typed throw new reference error then it should come. See, reference error has come "Harry is not good". Now if I do something like "error.stack", and then "Harry = " or let me just type console.log(harry) Ok and then, after doing this I reload it, Reference error harry is not defined, this stack prints here. Got it? So I can also print error.stack Now I'll tell you how to throw an custom error, I have explained this in the notes "for all the built in errors, the error object has 2 main principles: error and message" And you can also print stack sometimes. and you can throw your own error by using throw syntax. Like here, if age > 80 then print invalid age. So let's quickly type a program, and with that program we'll ask users that let age = prompt("Enter your age") and after this we'll type if and I'll try all these things that if i get an error I'll catch it through catch. and I'll do one more thing here, The script is still running. Ok? and I tried age = prompt enter your age and then I'll definitely want to convert this into an integer. So for making it a integer I'll type age = Number.parsInt(age) and then console. log. And then if age > 120 I'll put throw new error, this is probably not true Let's do it 130 or 150, alright. Don't feel sad. This is probably not true. And after doing this, simply I'll save it I'll show you enter your age 89. The script is still running. And then I put a bit more. This is a reference error. This is probably not true. and "This is not true" comes as I also print error.stack. So you can do such things within your real time script. You can throw syntax error, reference error and many more types of error And you can search mdn reference js errors. And you'll get every error like range error, internal error You'll see all type of errors of javascript here. You can study them and then deploy too. Here you can learn how to deploy them but a good idea will be that You'll perform things like this whenever you please. So I hope you know how to throw custom errors, In next video we'll definitely talk about clause and a very handy use case of it where clause is actually used about which, many people don't know. We'll cover it in the next video. If you haven't accessed javascript playlist yet, or you are having trouble using my replits, so you should browse replit.com/@codewithharry and, access ultimate javascript course folder. You'll find every single replit there. You'll get every single one of them there. I did this so that you can directly clone all of this by using a fork and start doing your work. because otherwise it's a hassle to do. Unlike copying the code, you can fork it and use it directly here. You can run code directly inside the repl. Got it? So please access this playlist and save it. Thank you so much for watching this video guys. And I'll see you next time...