Reading the Trace of Your Own Error

Joan’s port now handles a missing export, and anything unexpected still crashes with a stack trace. From crash reports, you know that the first at line is where it happened and that the node:internal frames at the bottom aren’t yours. This time you threw the error yourself. You’ll find the frame that passed the bad value and keep the trace when you catch the error.

Read the Trace From the Top

The finished checkRows() will catch each RangeError from parseAmount() and reject the row. To see where one comes from, Joan runs a copy without that catch on the first three lines of October’s export:

Language: JavaScript Filename: traces.js
function parseAmount(text) {
  const amount = Number(text);
  if (text.trim() === "" || !Number.isFinite(amount)) {
    throw new RangeError(`amount is not a number, got "${text}"`);
  }
  if (amount <= 0) {
    throw new RangeError(`amount must be positive, got ${amount}`);
  }
  return amount;
}

function checkRows(lines) {
  let total = 0;
  for (const line of lines.slice(1)) {
    const [date, donor, amountText] = line.split(";");
    total += parseAmount(amountText);
  }
  return total;
}

const lines = [
  "date;donor;amount",
  "2026-10-03;D-101;50.00",
  "2026-10-07;D-102;n/a",
];
console.log(checkRows(lines));

D-102’s "n/a" stops the script:

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.