Hacker News new | past | comments | ask | show | jobs | submit login

  function calculatePaymentAmount(payment) {
    if(typeof payment.payByCard != "number") throw new Error("payment.payByCard=" + payment.payByCard);
    if(typeof payment.cardFee != "number") throw new Error("payment.cardFee=" + payment.cardFee);
    if(typeof payment.payByCash != "number") throw new Error("payment.payByCash=" + payment.payByCash);
    if(typeof payment.cashDiscount != "number") throw new Error("payment.cashDiscount=" + payment.cashDiscount);
	
    if(payment.payByCash <= 0 && payment.cashDiscount != 0) throw new Error("payment.payByCash=" + payment.payByCash + " payment.cashDiscount=" + payment.cashDiscount);
	
    return payment.payByCard + payment.payByCard * payment.cardFee + payment.payByCash - payment.cashDiscount;
  }
When an error is thrown, a core-dump should be generated, logged, and a developer notified, and the app should restart. The compiler can only catch so many bugs.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: