JavaScript Error Handling in Depth for Pythonistas (Summary)

You’ve reached the end of the course! Joan’s donation import can now follow the trustees’ all-or-nothing rule in JavaScript: report every bad row together and import nothing until the export is ready. You can also explain a missing export and pause the script when a report needs investigating.

The finished import keeps the Python script’s reports and exit codes, including the corrected export’s total of £1,430.00 from five donations. The missing-file cause uses each runtime’s own wording, so that line differs between Python and JavaScript.

You now have the tools to:

  • Define a family of errors under DonationError, with ExportMissingError and BadRowError for the import’s different failures. Set extra fields after super() and name subclasses in the base constructor with this.name = new.target.name.
  • Keep the original error when you wrap it in a clearer one. Pass { cause: err }, forward options through your constructors to super(), and read err.cause for the report’s second line.
  • Collect bad rows and throw new AggregateError(problems, message), with the errors first. Catch the group by its own class and read its children through err.errors.
  • Pause and step through the import with node inspect, Chrome DevTools, or VS Code. Inspect the row’s variables and use conditional breakpoints to stop only on the row you need.

Keep the Error Handling Deliberate

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.