try
{
//Run some code here
}
catch(err)
{
//Handle errors here
}
You can also throw exceptions as in c#
throw 'something went wrong !';
The exception can be a JavaScript String, a Number, a Boolean or an Object.
solved Equivalent of try catch(exception handling) in JavaScript [closed]