try catch javascript

JavaScript
try {
  // Try to run this code 
}
catch(err) {
  // if any error, Code throws the error
}
finally {
  // Always run this code regardless of error or not
  //this block is optional
}var someNumber = 1;
try {
  someNumber.replace("-",""); //You can't replace a int
} catch(err) {
 console.log(err);
}try {
console.log('hello');
}
catch (e){
}
try {
  // code may cause error
} catch(error){
  // code to handle error
}
Source

Also in JavaScript: