Add a separate class of exceptions for NumberReducer.

This commit is contained in:
Danila Fedorin 2017-09-22 11:58:19 -07:00
parent 76fcd8ec1c
commit 8dc7acd4b3
4 changed files with 33 additions and 12 deletions

View File

@ -0,0 +1,25 @@
package org.nwapw.abacus.exception;
/**
* Exception thrown by the NumberReducer if something goes wrong when
* transforming a parse tree into a single value.
*/
public class NumberReducerException extends AbacusException {
/**
* Creates a new NumberReducerException with
* no additional message.
*/
public NumberReducerException() {
this("");
}
/**
* Creates a new NumberReducerException with the given message.
* @param message the message.
*/
public NumberReducerException(String message) {
super("Error evaluating expression", message);
}
}

View File

@ -1,16 +1,14 @@
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.
* An exception thrown from TreeReducers.
*/
public class EvaluationException extends AbacusException {
public class ReductionException extends AbacusException {
/**
* Creates a new EvaluationException with the default string.
*/
public EvaluationException() {
public ReductionException() {
this("");
}
@ -18,7 +16,7 @@ public class EvaluationException extends AbacusException {
* Creates a new EvaluationError with the given message string.
* @param message the message string.
*/
public EvaluationException(String message) {
public ReductionException(String message) {
super("Evaluation error", message);
}

View File

@ -2,7 +2,8 @@ package org.nwapw.abacus.tree
import org.nwapw.abacus.Abacus
import org.nwapw.abacus.context.EvaluationContext
import org.nwapw.abacus.exception.EvaluationException
import org.nwapw.abacus.exception.NumberReducerException
import org.nwapw.abacus.exception.ReductionException
import org.nwapw.abacus.number.NumberInterface
class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<NumberInterface> {
@ -24,7 +25,7 @@ class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<Nu
if(variable != null) return variable
val definition = context.getDefinition(treeNode.variable)
if(definition != null) return definition.reduce(this)
throw EvaluationException("variable is not defined.")
throw NumberReducerException("variable is not defined.")
}
is NumberUnaryNode -> {
val child = children[0] as NumberInterface
@ -57,7 +58,7 @@ class NumberReducer(val abacus: Abacus, context: EvaluationContext) : Reducer<Nu
abacus.pluginManager.treeValueFunctionFor(treeNode.callTo)
.apply(context, *treeNode.children.toTypedArray())
}
else -> throw EvaluationException("unrecognized tree node.")
else -> throw ReductionException("unrecognized tree node.")
}
}

View File

@ -13,11 +13,8 @@ import javafx.util.StringConverter;
import org.nwapw.abacus.Abacus;
import org.nwapw.abacus.config.Configuration;
import org.nwapw.abacus.exception.AbacusException;
import org.nwapw.abacus.exception.ComputationInterruptedException;
import org.nwapw.abacus.function.Documentation;
import org.nwapw.abacus.function.DocumentationType;
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;