use of org.matheclipse.core.eval.exception.BreakException 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