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)andfinally, limiting thetryblock to the call that can fail - Check a key with
Object.hasOwn(), or provide a default for a missing ornullvalue with?? 0, since a missing key givesundefinedwithout raising an error - Throw an
Error,RangeErrororTypeErrorwhose message says what arrived - Filter inside the catch with
instanceofanderr.code, and rethrow the rest withthrow 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 withconsole.dir(value, { depth: null }), and useconsole.table()andconsole.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).