Skip to content

Commit

Permalink
fixed catch of stackoverflow to create the right stack trace
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Mar 11, 2024
1 parent 68b422b commit 6595ea8
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/org/rascalmpl/semantics/dynamic/Statement.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.rascalmpl.ast.QualifiedName;
import org.rascalmpl.ast.Target;
import org.rascalmpl.ast.Type;
import org.rascalmpl.exceptions.RascalStackOverflowError;
import org.rascalmpl.exceptions.RuntimeExceptionFactory;
import org.rascalmpl.interpreter.Accumulator;
import org.rascalmpl.interpreter.AssignableEvaluator;
Expand Down Expand Up @@ -959,14 +960,14 @@ static public Result<IValue> evalStatementTry(IEvaluator<Result<IValue>> eval, o
if (!handled)
throw e;
}
catch (StackOverflowError e) {
// and now we pretend as if a Rascal stackoverflow has been thrown, such that
catch (RascalStackOverflowError e) {
// and now we pretend as if a real Stackoverflow() value has been thrown, such that
// it can be caugt in this catch block if necessary:
boolean handled = false;

for (Catch c : handlers) {
if (c.hasPattern() && isCatchStackOverflow(c.getPattern())) {
IValue pseudo = RuntimeExceptionFactory.stackOverflow().getException();
IValue pseudo = e.makeThrow().getException();

if (Cases.matchAndEval(makeResult(pseudo.getType(), pseudo, eval), c.getPattern().buildMatcher(eval, false), c.getBody(), eval)) {
handled = true;
Expand All @@ -976,6 +977,7 @@ static public Result<IValue> evalStatementTry(IEvaluator<Result<IValue>> eval, o
}

if (!handled) {
// we rethrow because higher up the stack may be another catch block
throw e;
}
}
Expand Down

0 comments on commit 6595ea8

Please sign in to comment.