The Error Object & Custom Errors | JavaScript Tutorial in Hindi #61

The Error Object & Custom Errors | JavaScript Tutorial in Hindi #61


The Error Object & Custom Errors | JavaScript Tutorial in Hindi #61

Link to the Repl - https://replit.com/@codewithharry/61e
Join Replit - https://join.replit.com/CodeWithHarry
Download Notes - https://drive.google.com/drive/folder
Ultimate JS Course Playlist:    • JavaScript Tutorials for Beginners in…  
►Checkout my English channel here:    / @programmingwithharry  
►Instagram: www.instagram.com/codewithharry

python, C, C++, Java, JavaScript and Other Cheetsheets [++]:
Playlist:    • Coding CheatSheets 🧾 by CodeWithHarry  

►Learn in One Video[++]:
Python[15 Hr]:    • Python Tutorial For Beginners In Hind…  
Python Advance[3.5 Hr]:    • Python Programming Course in Hindi (A…  
Python[1 Hr]:    • Learn Python In Hindi In One Video - …  
Python[2 Hr]:    • Python Tutorial In Hindi 🔥  
Python[15 Min]:   • 15 Minute Python Tutorial For Beginne…  
JavaScript[1 Hr]:    • JavaScript Tutorial  
C[1.3 Hr]-   • C Programming Tutorial For Beginners:…  
php[1 Hr]:    • Learn Php In One Video In Hindi - हिं…  
php[2.3 Hr]:   • Php Tutorial for Beginners in Hindi w…  
php[Project]-    • Login And Registration Form Using Php…  
HTML[30 Min]:   • HTML 5 Tutorial For Beginners In Hind…  
CSS[8.5 Hr]:   • CSS Tutorial In Hindi (With Notes) 🔥  
CSS[1.4 Hr]:   • CSS 3 Tutorial For Beginners: Learn C…  
Wordpress[3.2 Hr]:   • How To Make a WordPress Website | Wor…  
Angular[2 Hr]:   • Angular Tutorial in Hindi  
Java[2.3 Hr]:   • Java tutorial in hindi 🔥  
Web Scraping[1 Hr]:   • Web Scraping Tutorial using Python an…  
MongoDB[2 Hr]:   • MongoDb Tutorial For Beginners in Hin…  
Numpy[1 Hr]:   • Numpy Tutorial in Hindi  
Android Dev[12 Hr]-    • Android Development Tutorial For Begi…  
Linux[1 Hr]:   • Linux Tutorial For Beginners in Hindi  
JQuery[1.1 Hr]:   • jQuery Tutorial For Beginners In Hind…  
Git and GitHub[1.1 Hr]:   • Git \u0026 GitHub Tutorial For Beginners I…  

►Complete course [playlist]:
React:    • React Js Tutorials in Hindi  
Python-   • Python Tutorials For Absolute Beginne…  
OOP Python-   • Object Oriented Programming Tutorials…  
Java:   • Java Tutorials For Beginners In Hindi  
JavaScript-    • JavaScript Tutorials In Hindi  
PHP-   • PHP Tutorials in Hindi  
C-   • C Language Tutorials In Hindi  
C++-   • C++ Tutorials In Hindi  
Git \u0026 GitHub-   • Git and GitHub Tutorials In Hindi  
Android Dev-    • Android Development Tutorials in Hindi  
Python GUI-    • Python GUI: Tkinter Tutorial In Hindi…  
Web Development-    • Web Development Tutorials For Beginne…  
Python Django:   • Python Django Tutorials In Hindi  
Projects Using HTML, CSS \u0026 Javascript-    • Projects Using HTML, CSS \u0026 JavaScript…  
Data Structure and Algo:   • Data Structures and Algorithms Course…  

Follow Me On Social Media
►Website (created using Django Rest \u0026 Angular): https://www.codewithharry.com
►Facebook:   / codewithharry  
►Instagram:   / codewithharry  
Twitter:   / codewithharry  
Comment “#HarryBhai” if you read this 😉😉


Content

0.107 -> Guys, in today's video we'll see what error objects are.
3.313 -> How do error objects work? And how can you throw a custom error?
6.999 -> For example, if the user puts in the wrong information, then I want
10.605 -> to throw a custom error to the user.
12.999 -> How is this done in JavaScript? Let's go to our computer screen and get started...
23.545 -> So, guys, let's learn about error objects.
25.756 -> As a result, I'd like to create a new repl.
28.317 -> I'll simply make a new repl and that will
33.402 -> Wait a minute...
37.209 -> I'll go to my profile and then,
40.475 -> We'll talk about error objects.
43.098 -> Now if you don't know what they are,
45.202 -> so the "err" from our last session is the error
47.618 -> object, about which we'll talk in detail today.
50.036 -> This is our video no. 61,
54.202 -> so I'll type "61_error_object".
59.695 -> Let's create a repl and move to our notes.
62.289 -> "For all the built in errors, the error object has 2 main properties"
65.967 -> Error object has 2 properties for built in errors.
68.702 -> What are they?
70.232 -> "name" and "message" are the two properties.
73.677 -> We rarely see stack, but these 2 are the main properties. So let's
79.343 -> produce an error and then we'll see how we can
83.828 -> use try catch error. So I'll take try catch error and in try I'll type
88.659 -> "Harry", which is a variable and is not defined,so it's obvious
92.853 -> that we'll see an error.
94.442 -> And we want to see that error so that,
98.783 -> we understand these things. So please focus here
103.422 -> I'll type console.log
107.9 -> So I just typed harry here.
111.782 -> and it prints "harry is not defined". This whole error prints here. But if I write
119.285 -> error.message, then see how this changes. Rather than
122.531 -> doing this, I'll put in error.name and error.message and run them.
127.523 -> So I'll type error.name
130.015 -> and I'll type error.message. So name done, message done;
134.667 -> Let me reload so that you can see what name is
138.848 -> Name is a reference error.
142.335 -> And this "harry is not defined" is the message.
145.633 -> So we can use this error's name and message
149.633 -> to indicate or identify or to take a set of actions when a reference error occurs.
155.795 -> Do this if you get a syntax error, or do this for something else.
159.423 -> Now let's say I want to throw custom errors here.
161.912 -> I'll only tell you how to throw custom errors.
164.756 -> If you want to throw custom errors and you type
169.352 -> "throw new error" and then
175.458 -> you type "Harry is not good" and throw this error here;
180.889 -> and reload it. So you'll see
183.695 -> this is an error and "harry is no" which is also an error. Now if I type throw new
188.591 -> reference error.
191.404 -> Then you'll get "type of error: reference error". Let me reload this properly.
200.092 -> Let's save this. If I typed throw new reference error then it should come.
206.432 -> See, reference error has come "Harry is not good".
210.085 -> Now if I do something like "error.stack",
215.35 -> and then "Harry = "
220.942 -> or let me just type console.log(harry)
228.488 -> Ok and then,
232.76 -> after doing this I reload it,
235.44 -> Reference error harry is not defined, this stack prints here. Got it?
240.032 -> So I can also print error.stack
242.705 -> Now I'll tell you how to throw an custom error, I have explained this in the notes
247.451 -> "for all the built in errors, the error object
249.871 -> has 2 main principles: error and message"
252.061 -> And you can also print stack sometimes.
255.529 -> and you can throw your own error by using throw syntax.
261.441 -> Like here, if age > 80 then print invalid age. So let's quickly type a program,
267.721 -> and with that program we'll ask users that
273.439 -> let age = prompt("Enter your age")
282.269 -> and after this we'll type if
286.1 -> and I'll try all these things that if i get an error I'll catch it through catch.
290.806 -> and I'll do one more thing here,
295.718 -> The script is still running. Ok?
300.356 -> and I tried age = prompt enter your age and then
304.206 -> I'll definitely want to convert this into an integer.
308.793 -> So for making it a integer I'll type
312.603 -> age = Number.parsInt(age)
319.085 -> and then console. log.
322.182 -> And then if age > 120
328.355 -> I'll put throw new error, this is probably not true
333.909 -> Let's do it 130 or 150, alright. Don't feel sad. This is probably
341.258 -> not true. And after doing this,
346.701 -> simply I'll save it I'll show you
350.54 -> enter your age 89. The script is still running. And then
357.664 -> I put a bit more. This is a reference error. This is probably not true.
362.67 -> and "This is not true" comes as I also print error.stack.
367.63 -> So you can do such things within your real time script.
370.936 -> You can throw syntax error, reference error and many more types of error
377.24 -> And you can search mdn reference js errors.
382.719 -> And you'll get every error like range error, internal error
386.731 -> You'll see all type of errors of javascript here.
390.342 -> You can study them and then deploy too.
395.356 -> Here you can learn how to deploy them but a good idea will be that
399.995 -> You'll perform things like this whenever you please.
402.839 -> So I hope you know how to throw custom errors,
405.189 -> In next video we'll definitely talk about clause and a very handy use case of it
409.314 -> where clause is actually used about which, many people don't know.
414.022 -> We'll cover it in the next video.
416.031 -> If you haven't accessed javascript playlist yet,
418.669 -> or you are having trouble using my replits,
423.615 -> so you should browse replit.com/@codewithharry and,
428.906 -> access ultimate javascript course folder. You'll find every single replit there.
436.393 -> You'll get every single one of them there.
438.717 -> I did this so that you can directly clone all of this by using a fork
442.258 -> and start doing your work. because otherwise it's a hassle to do.
445.601 -> Unlike copying the code, you can fork it and use it directly here.
451.891 -> You can run code directly inside the repl. Got it?
457.37 -> So please access this playlist and save it.
460.871 -> Thank you so much for watching this video guys.
464.374 -> And I'll see you next time...

Source: https://www.youtube.com/watch?v=uOQBGKfldIg