Answers for "proper handling using try, catch finally blocks in js"

1

try catch finally in javascript

try { // Try to run this code
  alert( 'try' ); 
  if (confirm('Make an error?')) BAD_CODE();
} catch (e) { // Code throws error
  alert( 'catch' );
} finally { // Always run this code regardless of error or not
  alert( 'finally' );
}
Posted by: Guest on January-26-2021
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