Skip to content

Commit 04e7ee1

Browse files
committed
Refactor Exception handling
1 parent 3bbd7bd commit 04e7ee1

File tree

15 files changed

+110
-136
lines changed

15 files changed

+110
-136
lines changed

symja-parser/src/main/java/org/matheclipse/parser/client/eval/ComplexEvalVisitor.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.matheclipse.parser.client.eval.api.function.PlusFunction;
4646
import org.matheclipse.parser.client.eval.api.function.SetFunction;
4747
import org.matheclipse.parser.client.eval.api.function.TimesFunction;
48-
import org.matheclipse.parser.client.math.MathException;
48+
import org.matheclipse.parser.client.math.ArithmeticMathException;
4949

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

329329
/**
@@ -431,7 +431,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
431431
if (complexOnly) {
432432
try {
433433
return new ComplexNode(visit(functionNode));
434-
} catch (Exception e) {
434+
} catch (RuntimeException e) {
435435

436436
}
437437
}

symja-parser/src/main/java/org/matheclipse/parser/client/eval/DoubleEvaluator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
867867
if (doubleOnly) {
868868
try {
869869
return new DoubleNode(evaluateFunction(functionNode));
870-
} catch (Exception e) {
870+
} catch (RuntimeException e) {
871871

872872
}
873873
}

symja-parser/src/main/java/org/matheclipse/parser/client/eval/api/AbstractASTVisitor.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@
3232
import org.matheclipse.parser.client.eval.ComplexNode;
3333
import org.matheclipse.parser.client.eval.DoubleNode;
3434
import org.matheclipse.parser.client.math.ArithmeticMathException;
35-
import org.matheclipse.parser.client.math.MathException;
3635

3736
/**
3837
* Abstract AST visitor with empty default method implementations.
@@ -225,7 +224,7 @@ public T visit(FunctionNode functionNode) {
225224
}
226225
}
227226
}
228-
throw new MathException(
227+
throw new ArithmeticMathException(
229228
"AbstractASTVisitor#evaluateFunction(FunctionNode) not possible for: " + functionNode.toString());
230229

231230
}
@@ -256,7 +255,7 @@ public T visit(SymbolNode node) {
256255
if (c != null) {
257256
return c;
258257
}
259-
throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString());
258+
throw new ArithmeticMathException("ComplexEvalVisitor#visit(SymbolNode) not possible for: " + node.toString());
260259

261260
}
262261
}

symja-parser/src/main/java/org/matheclipse/parser/client/eval/bigfraction/BigFractionEvalVisitor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -922,7 +922,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
922922
// if (dfpOnly) {
923923
// try {
924924
// return new BigFractionNode(evaluateFunction(functionNode));
925-
// } catch (Exception e) {
925+
// } catch (RuntimeException e) {
926926
//
927927
// }
928928
// }

symja-parser/src/main/java/org/matheclipse/parser/client/eval/dfp/DfpEvalVisitor.java

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@
5656
import org.matheclipse.parser.client.eval.api.function.SetFunction;
5757
import org.matheclipse.parser.client.eval.api.function.TimesFunction;
5858
import org.matheclipse.parser.client.math.ArithmeticMathException;
59-
import org.matheclipse.parser.client.math.MathException;
6059
import org.matheclipse.parser.client.operator.ASTNodeFactory;
6160

6261
/**
@@ -1001,7 +1000,7 @@ public ASTNode optimizeFunction(final FunctionNode functionNode) {
10011000
if (dfpOnly) {
10021001
try {
10031002
return new DfpNode(evaluateFunction(functionNode));
1004-
} catch (Exception e) {
1003+
} catch (RuntimeException e) {
10051004

10061005
}
10071006
}
@@ -1089,17 +1088,4 @@ public Dfp visit(StringNode node) {
10891088
return null;
10901089
}
10911090

1092-
// @Override
1093-
// public Dfp visit(SymbolNode node) {
1094-
// FieldElementVariable<Dfp> v = fVariableMap.get(node.toString());
1095-
// if (v != null) {
1096-
// return v.getValue();
1097-
// }
1098-
// Dfp c = SYMBOL_DFP_MAP.get(node.toString());
1099-
// if (c != null) {
1100-
// return c;
1101-
// }
1102-
// throw new MathException("ComplexEvalVisitor#visit(SymbolNode) not
1103-
// possible for: " + node.toString());
1104-
// }
11051091
}
Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
package org.matheclipse.parser.client.math;
22

3-
public class ArithmeticMathException extends MathException {
3+
import org.apache.commons.math3.exception.MathRuntimeException;
4+
import org.apache.commons.math3.exception.util.LocalizedFormats;
5+
6+
public class ArithmeticMathException extends MathRuntimeException {
7+
48
/**
59
*
610
*/
7-
private static final long serialVersionUID = -7859219482948928259L;
11+
private static final long serialVersionUID = -9048053527631483568L;
12+
13+
final String fMessage;
814

915
public ArithmeticMathException(String message) {
10-
super(message);
16+
super(LocalizedFormats.ILLEGAL_STATE);
17+
fMessage = message;
18+
}
19+
20+
@Override
21+
public String getLocalizedMessage() {
22+
return fMessage;
23+
}
24+
25+
@Override
26+
public String getMessage() {
27+
return fMessage;
1128
}
1229
}

symja-parser/src/main/java/org/matheclipse/parser/client/math/MathException.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

symja-parser/src/main/java/org/matheclipse/parser/util/Console.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public String interpreter(final String strEval) {
190190
} catch (MathRuntimeException e) {
191191
System.err.println();
192192
System.err.println(e.getMessage());
193-
} catch (Exception e) {
193+
} catch (RuntimeException e) {
194194
e.printStackTrace();
195195
}
196196
return "";

0 commit comments

Comments
 (0)