From 3327f43798105ec3977e7536b20dab1abdc59539 Mon Sep 17 00:00:00 2001 From: xiaowei-zhang Date: Fri, 3 Apr 2020 15:21:14 +0200 Subject: [PATCH] Accurate error messages Add one more condition to trigger accurate error messages --- .../scala/scalatutorial/sections/ImperativeProgramming.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/scala/scalatutorial/sections/ImperativeProgramming.scala b/src/main/scala/scalatutorial/sections/ImperativeProgramming.scala index 1323496f..5154f9cf 100644 --- a/src/main/scala/scalatutorial/sections/ImperativeProgramming.scala +++ b/src/main/scala/scalatutorial/sections/ImperativeProgramming.scala @@ -115,9 +115,11 @@ object ImperativeProgramming extends ScalaTutorialSection { * balance * } * def withdraw(amount: Int): Int = - * if (0 < amount && amount <= balance) { + * if (0 <= amount && amount <= balance) { * balance = balance - amount * balance + * } else if (amount < 0) { + * throw new Error("invalid withdraw amount") * } else throw new Error("insufficient funds") * } * }}}