Learn JavaScript

Lesson 2 of 9 · Error Handling: throw, try, catch, finally, and Reading a Stack Trace

Module 10 · Error Handling: throw, try, catch, finally, and Reading a Stack Trace

Every Piece of Error Handling, One by One: finally, the Built-in Kinds, Your Own Errors and the Stack Trace

Free with an accountReading

Kenji maintains the import tool of a small online shop. It reads supplier files, parses JSON, checks prices and writes the result. Each step can fail in its own way. A missing file, a broken JSON line, a negative price and a plain bug in his own code all reach the same catch today. The tool prints "something went wrong" for every one of them. Kenji cannot tell a supplier's mistake from his own.

Checking what this lesson needs for you…

What is inside Every Piece of Error Handling, One by One: finally, the Built-in Kinds, Your Own Errors and the Stack Trace

  1. throw takes any value, and an Error is the one to give
  2. new Error, and its name, message and stack
  3. try and catch
  4. The optional catch binding
  5. finally, and the order of the three
  6. TypeError: the wrong kind of value
  7. ReferenceError: a name that does not exist yet
  8. RangeError: a number outside what is allowed
  9. SyntaxError: text that does not parse
  10. URIError, and EvalError by name
  11. instanceof tells the kinds apart
  12. Your own errors: extends Error, and the name fix
  13. Extra fields: a code the program can read
  14. The cause option: one error wrapping another
  15. Rethrowing what you cannot handle
  16. Reading a stack trace, line by line
  17. Which error does Node throw?