Error Handling in JavaScript

If we write code there will must be create some errors. It’s a good way to not to understand there are error in the application. From this thinking there comes the name of Error Handling. Today we’ll discuss about this. For this we’ll use try…catch statements.

Photo by Kevin Ku on Unsplash

Example:

Try Statement

2. Catch Statement: The catch block contains the statement that specify what to do if the try statement throws the error . It catches the error thrown by the try block.

Example:

Catch Statement

3. Throw Statement: With this statement we can throw custom errors. This statement is usually used on conditions.

Example:

Throw Statement

4. Finally Statement: These statements run after try statements and catch statements. The code from the finally statement always run is there any error thrown by the try statement or not.

Example:

Finally Statements

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store