try / catch

  • Sometimes operations fail
  • It would be nice to be able to handle errors gracefully
  • Errors immediately exit the current function and keep bubbling up until something catches them
  • try / catch in JavaScript lets you do this
  • You can catch an error and handle it
try {
    someSketchyFunction(); // This function might fail
} catch (e) {
    console.error(e.message) // What to do with the failure
}

6 / 23