From 55257f72747ebfe5e09a2ac3cf69614dfd42fbbe Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Sat, 5 Aug 2017 15:58:43 -0700 Subject: [PATCH] Fix exception handling. --- .../org/nwapw/abacus/fx/AbacusController.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/src/main/java/org/nwapw/abacus/fx/AbacusController.java index 459508c..d514237 100644 --- a/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -51,6 +51,10 @@ public class AbacusController implements PluginListener { * Constant string that is displayed if the calculations are stopped before they are done. */ private static final String ERR_STOP = "Stopped"; + /** + * Constant string that is displayed if the calculations are interrupted by an exception. + */ + private static final String ERR_EXCEPTION = "Exception Thrown"; @FXML private TabPane coreTabPane; @FXML @@ -118,11 +122,11 @@ public class AbacusController implements PluginListener { private final Runnable CALCULATION_RUNNABLE = new Runnable() { private String attemptCalculation(){ - TreeNode constructedTree = abacus.parseString(inputField.getText()); - if (constructedTree == null) { - return ERR_SYNTAX; - } try { + TreeNode constructedTree = abacus.parseString(inputField.getText()); + if (constructedTree == null) { + return ERR_SYNTAX; + } NumberInterface evaluatedNumber = abacus.evaluateTree(constructedTree); if (evaluatedNumber == null) { return ERR_EVAL; @@ -132,6 +136,9 @@ public class AbacusController implements PluginListener { return resultingString; } catch (ComputationInterruptedException exception) { return ERR_STOP; + } catch (RuntimeException exception){ + exception.printStackTrace(); + return ERR_EXCEPTION; } }