Errors, tests and debugging
This part of the JavaScript course is about failure: an error is a value that is thrown, caught and finally passed on, and the part starts with try, catch and the Error class. A custom class carries a name and a cause, and a handler collects several problems into an AggregateError or rethrows one with its cause. Tests follow: the assertions of node:assert/strict, the node:test runner and a fake clock in place of the real one. The part ends with the console, a stack trace read frame by frame and the inspector.
073
Errors: throw, try, catch and finally
throw and the uncaught exit code, try and catch around any value, finally that runs on every path, the Error class and its name, message and stack
Open
074
Custom error classes
a class that extends Error, the name field, the cause option that keeps the original, and instanceof through the chain of a handler
Open
075
Error handling patterns
problems collected in one pass with AggregateError, an error wrapped and rethrown with its cause, the functions that should not catch, and one boundary that sets the exit code
Open
076
Assertions and the node:test runner
node:assert/strict, equal against deepEqual, assert.throws with a class and a pattern, the node:test runner, the dot reporter and the exit code
Open
077
Testing with fakes: a clock and a file
a function that reads Date.now itself, the moment as a parameter, a fake clock in a test, and a store object that stands in for a file
Open
078
Debugging: console, the stack and the inspector
console.log and console.error on the two streams, console.table, a stack trace read frame by frame, node --inspect and the inspector module in a program
Open