From 45de25cd50f08a1404cd52e87006ebd5bc413974 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Thu, 7 Sep 2017 13:05:16 -0700 Subject: [PATCH] Move exceptions to their own package and subclass one class. --- .../java/org/nwapw/abacus/exception/AbacusException.java | 9 +++++++++ .../ComputationInterruptedException.java | 6 +++--- .../abacus/{function => exception}/DomainException.java | 8 ++++---- .../{function => exception}/EvaluationException.java | 8 ++++---- .../java/org/nwapw/abacus/number/NumberInterface.java | 2 ++ .../org/nwapw/abacus/function/applicable/Applicable.kt | 2 +- .../main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt | 2 +- .../java/org/nwapw/abacus/tests/CalculationTests.java | 2 +- .../main/java/org/nwapw/abacus/fx/AbacusController.java | 5 +++-- 9 files changed, 28 insertions(+), 16 deletions(-) create mode 100644 core/src/main/java/org/nwapw/abacus/exception/AbacusException.java rename core/src/main/java/org/nwapw/abacus/{number => exception}/ComputationInterruptedException.java (56%) rename core/src/main/java/org/nwapw/abacus/{function => exception}/DomainException.java (71%) rename core/src/main/java/org/nwapw/abacus/{function => exception}/EvaluationException.java (75%) diff --git a/core/src/main/java/org/nwapw/abacus/exception/AbacusException.java b/core/src/main/java/org/nwapw/abacus/exception/AbacusException.java new file mode 100644 index 0000000..894e959 --- /dev/null +++ b/core/src/main/java/org/nwapw/abacus/exception/AbacusException.java @@ -0,0 +1,9 @@ +package org.nwapw.abacus.exception; + +public class AbacusException extends RuntimeException { + + public AbacusException(String baseMessage, String description){ + super(baseMessage + ((description == null) ? "." : (": " + description))); + } + +} diff --git a/core/src/main/java/org/nwapw/abacus/number/ComputationInterruptedException.java b/core/src/main/java/org/nwapw/abacus/exception/ComputationInterruptedException.java similarity index 56% rename from core/src/main/java/org/nwapw/abacus/number/ComputationInterruptedException.java rename to core/src/main/java/org/nwapw/abacus/exception/ComputationInterruptedException.java index e055508..bd77649 100644 --- a/core/src/main/java/org/nwapw/abacus/number/ComputationInterruptedException.java +++ b/core/src/main/java/org/nwapw/abacus/exception/ComputationInterruptedException.java @@ -1,16 +1,16 @@ -package org.nwapw.abacus.number; +package org.nwapw.abacus.exception; /** * Exception thrown when the computation is interrupted by * the user. */ -public class ComputationInterruptedException extends RuntimeException { +public class ComputationInterruptedException extends AbacusException { /** * Creates a new exception of this type. */ public ComputationInterruptedException() { - super("Computation interrupted."); + super("Computation interrupted", null); } } diff --git a/core/src/main/java/org/nwapw/abacus/function/DomainException.java b/core/src/main/java/org/nwapw/abacus/exception/DomainException.java similarity index 71% rename from core/src/main/java/org/nwapw/abacus/function/DomainException.java rename to core/src/main/java/org/nwapw/abacus/exception/DomainException.java index 2d09dc3..4b7fe17 100644 --- a/core/src/main/java/org/nwapw/abacus/function/DomainException.java +++ b/core/src/main/java/org/nwapw/abacus/exception/DomainException.java @@ -1,24 +1,24 @@ -package org.nwapw.abacus.function; +package org.nwapw.abacus.exception; /** * Exception thrown if the function parameters do not match * requirements. */ -public class DomainException extends RuntimeException { +public class DomainException extends AbacusException { /** * Creates a new DomainException. * @param reason the reason for which the exception is thrown. */ public DomainException(String reason) { - super(reason); + super("Domain error", reason); } /** * Creates a new DomainException with a default message. */ public DomainException(){ - this("Domain error."); + this(null); } } diff --git a/core/src/main/java/org/nwapw/abacus/function/EvaluationException.java b/core/src/main/java/org/nwapw/abacus/exception/EvaluationException.java similarity index 75% rename from core/src/main/java/org/nwapw/abacus/function/EvaluationException.java rename to core/src/main/java/org/nwapw/abacus/exception/EvaluationException.java index 55db570..4763aaf 100644 --- a/core/src/main/java/org/nwapw/abacus/function/EvaluationException.java +++ b/core/src/main/java/org/nwapw/abacus/exception/EvaluationException.java @@ -1,17 +1,17 @@ -package org.nwapw.abacus.function; +package org.nwapw.abacus.exception; /** * An exception thrown primarily from Tree Value operators and functions, * which have to deal with the result of a Reducer as well as the results * of Applicable. */ -public class EvaluationException extends RuntimeException { +public class EvaluationException extends AbacusException { /** * Creates a new EvaluationException with the default string. */ public EvaluationException() { - super("Evaluation error."); + this(null); } /** @@ -19,7 +19,7 @@ public class EvaluationException extends RuntimeException { * @param message the message string. */ public EvaluationException(String message) { - super(message); + super("Evaluation error", message); } } diff --git a/core/src/main/java/org/nwapw/abacus/number/NumberInterface.java b/core/src/main/java/org/nwapw/abacus/number/NumberInterface.java index 4a3fe5c..8727425 100755 --- a/core/src/main/java/org/nwapw/abacus/number/NumberInterface.java +++ b/core/src/main/java/org/nwapw/abacus/number/NumberInterface.java @@ -1,5 +1,7 @@ package org.nwapw.abacus.number; +import org.nwapw.abacus.exception.ComputationInterruptedException; + /** * An interface used to represent a number. */ diff --git a/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt b/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt index 8d824a8..5103d8b 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/function/applicable/Applicable.kt @@ -1,7 +1,7 @@ package org.nwapw.abacus.function.applicable import org.nwapw.abacus.context.MutableEvaluationContext -import org.nwapw.abacus.function.DomainException +import org.nwapw.abacus.exception.DomainException /** * A class that can be applied to arguments. diff --git a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt b/core/src/main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt index 8f61923..e94ab46 100644 --- a/core/src/main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt +++ b/core/src/main/kotlin/org/nwapw/abacus/tree/NumberReducer.kt @@ -2,7 +2,7 @@ package org.nwapw.abacus.tree import org.nwapw.abacus.Abacus import org.nwapw.abacus.context.EvaluationContext -import org.nwapw.abacus.function.EvaluationException +import org.nwapw.abacus.exception.EvaluationException import org.nwapw.abacus.number.NumberInterface class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer { diff --git a/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java b/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java index af85be6..1aee10e 100755 --- a/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java +++ b/core/src/test/java/org/nwapw/abacus/tests/CalculationTests.java @@ -5,7 +5,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.nwapw.abacus.Abacus; import org.nwapw.abacus.config.Configuration; -import org.nwapw.abacus.function.DomainException; +import org.nwapw.abacus.exception.DomainException; import org.nwapw.abacus.number.NumberInterface; import org.nwapw.abacus.plugin.StandardPlugin; import org.nwapw.abacus.tree.TreeNode; diff --git a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java index f7fb44d..c05f03b 100644 --- a/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java +++ b/fx/src/main/java/org/nwapw/abacus/fx/AbacusController.java @@ -12,10 +12,11 @@ import javafx.util.Callback; import javafx.util.StringConverter; import org.nwapw.abacus.Abacus; import org.nwapw.abacus.config.Configuration; +import org.nwapw.abacus.exception.ComputationInterruptedException; import org.nwapw.abacus.function.Documentation; import org.nwapw.abacus.function.DocumentationType; -import org.nwapw.abacus.function.DomainException; -import org.nwapw.abacus.function.EvaluationException; +import org.nwapw.abacus.exception.DomainException; +import org.nwapw.abacus.exception.EvaluationException; import org.nwapw.abacus.number.*; import org.nwapw.abacus.plugin.ClassFinder; import org.nwapw.abacus.plugin.PluginListener;