Fish Touching🐟🎣

JavaScript Error Handling

Apr 3, 2023

# Try Catch

setTimeout(function() {
  try {
    noSuchVariable; // try...catch handles the error!
  } catch {
    alert( "error is caught here!" );
  }
}, 1000);

# Throw Operator

throw <error object>
let error = new Error(message);
let error = new SyntaxError(message);
let error = new ReferenceError(message);

# Finally

The finally clause is a great place to finish the measurements no matter what.

Variables are local inside try...catch...finally