From e7ef18add7a5671d17cdbff99a81690d0c4be4de Mon Sep 17 00:00:00 2001 From: as704245 Date: Wed, 9 Oct 2019 09:52:20 +0200 Subject: [PATCH] =?UTF-8?q?rajout=C3=A9=20m=C3=A9thode=20isParsable=20pour?= =?UTF-8?q?=20v=C3=A9rifier=20si=20parseInt=20dans=20setCode=20peut=20s'ex?= =?UTF-8?q?=C3=A9cuter=20et=20=C3=A9viter=20une=20possible=20exception?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NGCC/src/config/Config.java | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/NGCC/src/config/Config.java b/NGCC/src/config/Config.java index a0c2e01..766057a 100644 --- a/NGCC/src/config/Config.java +++ b/NGCC/src/config/Config.java @@ -27,6 +27,15 @@ public class Config { this.questions = questions; } + public boolean isParsable(String s) { + try { + Integer.valueOf(s); + return true; + } catch (NumberFormatException e) { + return false; + } + } + public Config(String s) { // Constructeur, prend en parametre le chemin vers le fichier source source = s; @@ -215,9 +224,11 @@ public class Config { public void setCode(String s) { s = s.trim(); - int n = Integer.parseInt(s); - if (n >= 1 && n <= 16) { - param.replace("Code", s); + if (isParsable(s)) { + int n = Integer.parseInt(s); + if (n >= 1 && n <= 16) { + param.replace("Code", s); + } } }