Answers for "try charch finally js"

113

javascript try catch finally

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
}
Posted by: Guest on June-12-2020
2

javascript try catch finally return

(function() {
  try {
    try {
      throw new Error('oops');
    } catch (ex) {
      console.error('inner', ex.message);
      throw ex;
    } finally {
      console.log('finally');
      return;
    }
  } catch (ex) {
    console.error('outer', ex.message);
  }
})();

// Output:
// "inner" "oops"
// "finally"
Posted by: Guest on December-11-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language