Skip to content

Commit

Permalink
Refactor Exception handling
Browse files Browse the repository at this point in the history
  • Loading branch information
axkr committed Feb 6, 2016
1 parent 3bbd7bd commit 04e7ee1
Show file tree
Hide file tree
Showing 15 changed files with 110 additions and 136 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
import org.matheclipse.parser.client.eval.api.function.PlusFunction;
import org.matheclipse.parser.client.eval.api.function.SetFunction;
import org.matheclipse.parser.client.eval.api.function.TimesFunction;
import org.matheclipse.parser.client.math.MathException;
import org.matheclipse.parser.client.math.ArithmeticMathException;

/**
* Abstract AST visitor with empty default method implementation.
Expand Down Expand Up @@ -323,7 +323,7 @@ public Complex visit(SymbolNode node) {
if (c != null) {
return c;
}
throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString());
throw new ArithmeticMathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString());
}

/**
Expand Down Expand Up @@ -431,7 +431,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
if (complexOnly) {
try {
return new ComplexNode(visit(functionNode));
} catch (Exception e) {
} catch (RuntimeException e) {

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
if (doubleOnly) {
try {
return new DoubleNode(evaluateFunction(functionNode));
} catch (Exception e) {
} catch (RuntimeException e) {

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import org.matheclipse.parser.client.eval.ComplexNode;
import org.matheclipse.parser.client.eval.DoubleNode;
import org.matheclipse.parser.client.math.ArithmeticMathException;
import org.matheclipse.parser.client.math.MathException;

/**
* Abstract AST visitor with empty default method implementations.
Expand Down Expand Up @@ -225,7 +224,7 @@ public T visit(FunctionNode functionNode) {
}
}
}
throw new MathException(
throw new ArithmeticMathException(
"AbstractASTVisitor#evaluateFunction(FunctionNode) not possible for: " + functionNode.toString());

}
Expand Down Expand Up @@ -256,7 +255,7 @@ public T visit(SymbolNode node) {
if (c != null) {
return c;
}
throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString());
throw new ArithmeticMathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -922,7 +922,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
// if (dfpOnly) {
// try {
// return new BigFractionNode(evaluateFunction(functionNode));
// } catch (Exception e) {
// } catch (RuntimeException e) {
//
// }
// }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import org.matheclipse.parser.client.eval.api.function.SetFunction;
import org.matheclipse.parser.client.eval.api.function.TimesFunction;
import org.matheclipse.parser.client.math.ArithmeticMathException;
import org.matheclipse.parser.client.math.MathException;
import org.matheclipse.parser.client.operator.ASTNodeFactory;

/**
Expand Down Expand Up @@ -1001,7 +1000,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
if (dfpOnly) {
try {
return new DfpNode(evaluateFunction(functionNode));
} catch (Exception e) {
} catch (RuntimeException e) {

}
}
Expand Down Expand Up @@ -1089,17 +1088,4 @@ public Dfp visit(StringNode node) {
return null;
}

// @Override
// public Dfp visit(SymbolNode node) {
// FieldElementVariable<Dfp> v = fVariableMap.get(node.toString());
// if (v != null) {
// return v.getValue();
// }
// Dfp c = SYMBOL_DFP_MAP.get(node.toString());
// if (c != null) {
// return c;
// }
// throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not
// possible for: " + node.toString());
// }
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
package org.matheclipse.parser.client.math;

public class ArithmeticMathException extends MathException {
import org.apache.commons.math3.exception.MathRuntimeException;
import org.apache.commons.math3.exception.util.LocalizedFormats;

public class ArithmeticMathException extends MathRuntimeException {

/**
*
*/
private static final long serialVersionUID = -7859219482948928259L;
private static final long serialVersionUID = -9048053527631483568L;

final String fMessage;

public ArithmeticMathException(String message) {
super(message);
super(LocalizedFormats.ILLEGAL_STATE);
fMessage = message;
}

@Override
public String getLocalizedMessage() {
return fMessage;
}

@Override
public String getMessage() {
return fMessage;
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public String interpreter(final String strEval) {
} catch (MathRuntimeException e) {
System.err.println();
System.err.println(e.getMessage());
} catch (Exception e) {
} catch (RuntimeException e) {
e.printStackTrace();
}
return "";
Expand Down
Loading

0 comments on commit 04e7ee1

Please sign in to comment.