Error Handling in JavaScript | Exception Handling in JavaScript | JavaScript Course for Beginners

preview_player
Показать описание
In this video, we'll be discussing how to handle errors in JavaScript. We'll cover how to create custom exceptions and handle them in a robust manner.

If you're new to programming, or you're just looking to improve your skills, this video is a great start. We'll be discussing the basics of exception handling in JavaScript, so you can build more robust and error-safe applications!
#javascript #exceptionhandling #errorhandling

In programming, exception handling is a process or method used for handling the abnormal statements in the code and executing them. It also enables to handle the flow control of the code/program.

For handling the code, various handlers are used that process the exception and execute the code. For example, the Division of a non-zero value with zero will result into infinity always, and it is an exception. Thus, with the help of exception handling, it can be executed and handled.

In exception handling:

A throw statement is used to raise an exception. It means when an abnormal condition occurs, an exception is thrown using throw.

The thrown exception is handled by wrapping the code into the try…catch block. If an error is present, the catch block will execute, else only the try block statements will get executed.

Thus, in a programming language, there can be different types of errors which may disturb the proper execution of the program.
Types of Errors

While coding, there can be three types of errors in the code:

Syntax Error: When a user makes a mistake in the pre-defined syntax of a programming language, a syntax error may appear.
Runtime Error: When an error occurs during the execution of the program, such an error is known as Runtime error. The codes which create runtime errors are known as Exceptions. Thus, exception handlers are used for handling runtime errors.
Logical Error: An error which occurs when there is any logical mistake in the program that may not produce the desired output, and may terminate abnormally. Such an error is known as Logical error.

Error Object

When a runtime error occurs, it creates and throws an Error object. Such an object can be used as a base for the user-defined exceptions too. An error object has two properties:

name: This is an object property that sets or returns an error name.
message: This property returns an error message in the string form.

try{} statement: Here, the code which needs possible error testing is kept within the try block. In case any error occur, it passes to the catch{} block for taking suitable actions and handle the error. Otherwise, it executes the code written within.

catch{} statement: This block handles the error of the code by executing the set of statements written within the block. This block contains either the user-defined exception handler or the built-in handler. This block executes only when any error-prone code needs to be handled in the try block. Otherwise, the catch block is skipped.

Throw Statement

Throw statements are used for throwing user-defined errors. User can define and throw their own custom errors. When throw statement is executed, the statements present after it will not execute. The control will directly pass to the catch block.

Social media Links:
To get the regular updates:
Playlists:
Virtual Coffee with Jagadeesh:
Digital Logic Design:
Computer Organization and Architecture:
C Programming:
Data Structures:

Theory of Computation:

Compiler Design:

Computer Networks:
For GATE PYQs and much more explore:
Рекомендации по теме
Комментарии
Автор

Thank you sir for detailed explanation...I loved your teaching
Tq so much❤❤
With this one video...I have subscribed your channel

kudalikalyani
visit shbcf.ru