mirror of
https://github.com/DanilaFe/abacus
synced 2024-11-19 00:49:32 -08:00
Fix exception handling.
This commit is contained in:
parent
2381c93fb5
commit
55257f7274
|
@ -51,6 +51,10 @@ public class AbacusController implements PluginListener {
|
||||||
* Constant string that is displayed if the calculations are stopped before they are done.
|
* Constant string that is displayed if the calculations are stopped before they are done.
|
||||||
*/
|
*/
|
||||||
private static final String ERR_STOP = "Stopped";
|
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
|
@FXML
|
||||||
private TabPane coreTabPane;
|
private TabPane coreTabPane;
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -118,11 +122,11 @@ public class AbacusController implements PluginListener {
|
||||||
private final Runnable CALCULATION_RUNNABLE = new Runnable() {
|
private final Runnable CALCULATION_RUNNABLE = new Runnable() {
|
||||||
|
|
||||||
private String attemptCalculation(){
|
private String attemptCalculation(){
|
||||||
|
try {
|
||||||
TreeNode constructedTree = abacus.parseString(inputField.getText());
|
TreeNode constructedTree = abacus.parseString(inputField.getText());
|
||||||
if (constructedTree == null) {
|
if (constructedTree == null) {
|
||||||
return ERR_SYNTAX;
|
return ERR_SYNTAX;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
NumberInterface evaluatedNumber = abacus.evaluateTree(constructedTree);
|
NumberInterface evaluatedNumber = abacus.evaluateTree(constructedTree);
|
||||||
if (evaluatedNumber == null) {
|
if (evaluatedNumber == null) {
|
||||||
return ERR_EVAL;
|
return ERR_EVAL;
|
||||||
|
@ -132,6 +136,9 @@ public class AbacusController implements PluginListener {
|
||||||
return resultingString;
|
return resultingString;
|
||||||
} catch (ComputationInterruptedException exception) {
|
} catch (ComputationInterruptedException exception) {
|
||||||
return ERR_STOP;
|
return ERR_STOP;
|
||||||
|
} catch (RuntimeException exception){
|
||||||
|
exception.printStackTrace();
|
||||||
|
return ERR_EXCEPTION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user