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
- throw takes any value, and an Error is the one to give
- new Error, and its name, message and stack
- try and catch
- The optional catch binding
- finally, and the order of the three
- TypeError: the wrong kind of value
- ReferenceError: a name that does not exist yet
- RangeError: a number outside what is allowed
- SyntaxError: text that does not parse
- URIError, and EvalError by name
- instanceof tells the kinds apart
- Your own errors: extends Error, and the name fix
- Extra fields: a code the program can read
- The cause option: one error wrapping another
- Rethrowing what you cannot handle
- Reading a stack trace, line by line
- Which error does Node throw?