From: Jérôme Benoit Date: Tue, 8 Jan 2019 13:42:35 +0000 (+0100) Subject: Throw an error for illegal arguments. X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=bcdec88755a4a44882edfbb96581294f77a6e1ed;p=Persons_Comparator.git Throw an error for illegal arguments. Signed-off-by: Jérôme Benoit --- 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) {