diff --git a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java index 4504b06..de46be0 100644 --- a/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java +++ b/Axel/src/de/hs_mannheim/informatik/spreadsheet/Spreadsheet.java @@ -126,8 +126,13 @@ public class Spreadsheet { result = "TODO"; // TODO else if (formula.startsWith("MAX(")) // e.g. MAX(A1:A10) -> Standardabweichung result = "TODO"; // TODO - else if (!formula.isEmpty()) - result = "" + calculate(formula); + else if (!formula.isEmpty()) { + try { + result = "" + calculate(formula); + } catch(ArithmeticException ae) { + result = "exc."; + } + } cells[row][col].setValue("" + result); } @@ -153,7 +158,7 @@ public class Spreadsheet { * @param formula The expression to be evaluated. * @return The result calculated. */ - private long calculate(String formula) { + private long calculate(String formula) throws ArithmeticException { Matcher m = Pattern.compile("([A-Z][0-9]*)|[-\\+\\*/]|[0-9]*").matcher(formula); long res = 0;