Congratulations, you made it to the end of the course! Joan’s donation import now runs in JavaScript as node donations.js october.csv. It prints the same summary line as donations.py, 6 rows, 4 rejected, total £125.00, and rejects the same four rows by line number. The reasons use parseAmount()’s own messages, and the refund reads -40 where Python says -40.0.
A missing export gets No such file: missing.csv and exit code 1, and an unexpected row, such as a short one, still crashes the program so Joan notices.
In this course, you learned how to:
- Catch the errors you expect with
try,catch (err)andfinally, limiting thetryblock to the call that can fail - Check for a key with
Object.hasOwn(), or provide a default value for a missing key with?? 0, instead of catching a miss that never throws - Throw an
Error, aRangeErroror aTypeErrorwhose message says what arrived - Filter inside the catch with
instanceofanderr.code, and rethrow the rest - Read the trace of your own error from the top, where the second frame usually names the caller that passed the bad value
- Log values with labels, in full and at every level with
console.error()andconsole.dir(), list records withconsole.table(), and askconsole.trace()who called a function