JavaScript Error Handling in Depth for Pythonistas (Summary)

You’ve finished the course and Joan’s port. node donations.js november.csv lists all three bad rows and imports nothing. A missing export explains itself in a “caused by” line, and the corrected export imports five donations for £1,430.00. Only that cause line differs from Python, since each runtime phrases its own file error message.

You now have the tools to:

  • Define a family of errors on one base class that names them with this.name = new.target.name, setting extra fields after super()
  • Wrap an error in a clearer one with { cause: err }, forwarding options to super(), and read the chain through err.cause
  • Collect many errors and throw them as one new AggregateError(problems, message), then handle them through err.errors
  • Pause and step through a script with node inspect, Chrome DevTools or VS Code

Keep the Habits That Carry Over

Give the program one base class for its own failures. Pass the original error on whenever you throw a new one. Catch by class, most specific first. One catch (err) receives every error, so end the instanceof chain with else { throw err; }, where Python lets an unmatched exception propagate.

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Become a Member to join the conversation.