From bcdec88755a4a44882edfbb96581294f77a6e1ed Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 8 Jan 2019 14:42:35 +0100 Subject: [PATCH] Throw an error for illegal arguments. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/Size.java | 4 +++- src/Weight.java | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Size.java b/src/Size.java index 0cecada..dfea96c 100644 --- a/src/Size.java +++ b/src/Size.java @@ -15,7 +15,9 @@ public class Size { public void setSize(int size) { if (validateSize(size)) { this.size = size; - } /* FIXME: raise an error */ + } else { + throw new IllegalArgumentException("Size must be between" + this.min + " and " + this.max); + } } private boolean validateSize(int size) { diff --git a/src/Weight.java b/src/Weight.java index 3f2a829..2a8c812 100644 --- a/src/Weight.java +++ b/src/Weight.java @@ -12,7 +12,9 @@ public class Weight { public void setWeight(int weight) { if (validateWeight(weight)) { this.weight = weight; - } /* FIXME: raise an error */ + } else { + throw new IllegalArgumentException("Weight cannot be negative or zero"); + } } private boolean validateWeight(int weight) { -- 2.34.1