use of org.matheclipse.core.eval.exception.IterationLimitExceeded in project symja_android_library by axkr.
the class EvalControlledCallable method call.
@Override
public IExpr call() {
EvalEngine.remove();
EvalEngine.setReset(fEngine);
final StringWriter buf = new StringWriter();
try {
// fEngine.reset();<>
IExpr preRead = S.$PreRead.assignedValue();
IExpr temp;
try {
if (preRead != null && preRead.isPresent()) {
temp = fEngine.evaluate(F.unaryAST1(preRead, fExpr));
} else {
temp = fEngine.evaluate(fExpr);
}
} catch (final IterationLimitExceeded e) {
// Iteration limit of `1` exceeded.
int iterationLimit = fEngine.getIterationLimit();
IOFunctions.printMessage(S.$IterationLimit, "itlim", F.list(iterationLimit < 0 ? F.CInfinity : F.ZZ(iterationLimit), fExpr), fEngine);
temp = F.Hold(fExpr);
} catch (final RecursionLimitExceeded e) {
// Recursion depth of `1` exceeded during evaluation of `2`.
int recursionLimit = fEngine.getRecursionLimit();
IOFunctions.printMessage(S.$RecursionLimit, "reclim2", F.list(recursionLimit < 0 ? F.CInfinity : F.ZZ(recursionLimit), fExpr), fEngine);
temp = F.Hold(fExpr);
}
// IExpr temp = fEngine.evaluate(fExpr);
if (!fEngine.isOutListDisabled()) {
fEngine.addInOut(fExpr, temp);
}
return temp;
} catch (org.matheclipse.core.eval.exception.TimeoutException e) {
return S.$Aborted;
} catch (final SyntaxError se) {
LOGGER.error("EvalControlledCallable.call() failed", se);
} catch (final RuntimeException re) {
Throwable me = re.getCause();
if (me instanceof MathException) {
Validate.printException(buf, me);
} else {
Validate.printException(buf, re);
}
LOGGER.error(buf);
} catch (final Exception | OutOfMemoryError | StackOverflowError e) {
LOGGER.debug("EvalControlledCallable.call() failed", e);
Validate.printException(buf, e);
LOGGER.error(buf);
}
return S.$Aborted;
}
use of org.matheclipse.core.eval.exception.IterationLimitExceeded in project symja_android_library by axkr.
the class ExprEvaluator method evalTryCatch.
public static IExpr evalTryCatch(final IExpr expr, EvalEngine[] engineRef) {
EvalEngine engine = engineRef[0];
EvalEngine.set(engine);
// engine.reset() must be done before parsing step
IExpr preRead = S.$PreRead.assignedValue();
IExpr temp;
try {
if (preRead != null && preRead.isPresent()) {
temp = engine.evaluate(F.unaryAST1(preRead, expr));
} else {
temp = engine.evaluate(expr);
}
} catch (ReturnException rex) {
LOGGER.debug("ExprEvaluator.evalTryCatch() failed", rex);
return rex.getValue();
} catch (BreakException | ContinueException conex) {
LOGGER.debug("ExprEvaluator.evalTryCatch() failed", conex);
IAST ast = F.Continue();
if (conex instanceof BreakException) {
ast = F.Break();
}
// No enclosing For, While or Do found for `1`.
IOFunctions.printMessage(S.Continue, "nofwd", F.list(ast), engine);
temp = F.Hold(ast);
} catch (ThrowException e) {
LOGGER.debug("ExprEvaluator.evalTryCatch() failed", e);
// Uncaught `1` returned to top level.
IAST ast = F.Throw(e.getValue());
IOFunctions.printMessage(S.Throw, "nocatch", F.list(ast), engine);
temp = F.Hold(ast);
} catch (IterationLimitExceeded e) {
LOGGER.debug("ExprEvaluator.evalTryCatch() failed", e);
// Iteration limit of `1` exceeded.
int iterationLimit = engine.getIterationLimit();
IOFunctions.printMessage(S.$IterationLimit, "itlim", F.list(iterationLimit < 0 ? F.CInfinity : F.ZZ(iterationLimit), expr), engine);
temp = F.Hold(expr);
} catch (RecursionLimitExceeded e) {
LOGGER.debug("ExprEvaluator.evalTryCatch() failed", e);
// Recursion depth of `1` exceeded during evaluation of `2`.
int recursionLimit = engine.getRecursionLimit();
IOFunctions.printMessage(S.$RecursionLimit, "reclim2", F.list(recursionLimit < 0 ? F.CInfinity : F.ZZ(recursionLimit), expr), engine);
temp = F.Hold(expr);
}
if (!engine.isOutListDisabled()) {
engine.addInOut(expr, temp);
}
return temp;
}
Aggregations