Error Handling

The program can be stopped due to a mistake in one of the programs, also due to the wrong input of the user and the program can be stopped, even if the server does not respond properly, the program can be stopped, the execution of the program can be stopped due to many reasons. Basically error handling to save.

Suppose a programming of 100 lines catches an error in line 3, then what will happen? The program will stop on that line, the other line will no longer work, number 4–100: the line will no longer work.

In that case, if you use error handling, the program will not stop at line 4–100 ‌ they will work, that is why it basically uses error handling.
Some keywords are used for error handling, there’s a syntax construct try … catch that allows us to “catch” errors so the script can, instead of dying, do something more reasonable.

The try … catch construct has two main blocks:
try and then catch,
Catch’s job is to handle the exception or error that will be caught.
And the job of try is where the error can come, that is, the main code will be in try.

try {
//code test
}
catch {
//handle error
}

If you use try block, you will also need to use catch block. If an error is caught in the try block, it will handle the catch block.
If no error is caught, the catch block will not do anything, just ignore the code of the try block

try {
alert( ‘’hi” );
alert(x);
alert(“bye”);
}
catch(err){
//handle error
alert(“inside catch block”);
}

Here hi will print and an error will appear but the program will not stop, it will go directly to the catch block and the inside catch block will print. Thus for try … catch to work, the code must be runnable. In other words, it should be valid JavaScript.

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Meet Etsy’s 2019 Interns!

How to Create a Linked List in JavaScript

JavaScript ES2021- New ES21 features you need to see

Node.js Frameworks Comparison for Your Back-end Solution: Express.js, Meteor.js, Sails.js, and more

Jest 101 for Lightning Web Components-Part 1 : Step-up & Terminologies

devera https://t.co/GLZab6dz5Y Thanks for Following us on Twitter!

You don’t know React JS

AngularConnect 2018 on-the-spot

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
Afroza Akter Ruma

Afroza Akter Ruma

More from Medium

Components and Interface Composition

SOLID — Single Responsibility Principle

How long should I wait to retry a failed async job? Here is the Exponential backoff

Beware of calling long running native code together with high throughput workload in the same JVM