JavaScript Errors and Debugging for Pythonistas (Summary)

You’ve finished the course and Joan’s port. node donations.js october.csv prints the same 6 rows, 4 rejected, total £125.00 as donations.py, rejecting the same four rows with parseAmount()’s own messages as reasons and -40 where Python says -40.0. A missing export gets No such file: missing.csv and exit code 1, and a short row still crashes so Joan notices.

In this course, you learned how to:

  • Catch errors with try, catch (err) and finally, limiting the try block to the call that can fail
  • Check a key with Object.hasOwn(), or provide a default for a missing or null value with ?? 0, since a missing key gives undefined without raising an error
  • Throw an Error, RangeError or TypeError whose message says what arrived
  • Filter inside the catch with instanceof and err.code, and rethrow the rest with throw err
  • Read your own error’s trace from the top, where the second frame shows who passed the bad value
  • Log values labelled with { total } and in full at every level with console.dir(value, { depth: null }), and use console.table() and console.trace()

Keep the Habits That Carry Over

throw does raise’s job, finally runs even past a return, and err.message does str(err)’s. RangeError does ValueError’s job for a value of the right kind that a function refuses, numeric or not. A value of the wrong kind gets TypeError. console.error(err) logs the stack, like logging.exception() rather than print(err).

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.