Hey todays topic is very intersting, today we will learn about error handling.
Accualy it dosen't matter how great we are at programming , sometime our script have error. Error may occur because of our mistake , an unknown code, an unexpected user input , and for a thousand reason we can have error. Usually a script stop due to error.
The “try…catch” syntax
The try...catch construct has two main blocks: try, and then catch:
try {
// code...
} catch (err) {
// error handling
}
It works like this:
- First the try code is executed. if there is no error then code is run avoiding the catch error.
- if try code executed and get some problem , cod stop and catch function catch the error with out kill the script so we have chance to handle it.
Top comments (0)