usethesource / rascal

The implementation of the Rascal meta-programming language (including interpreter, type checker, parser generator, compiler and JVM based run-time system)
http://www.rascal-mpl.org
Other
393 stars 78 forks source link

Missing try/finally #1929

Open jurgenvinju opened 2 months ago

jurgenvinju commented 2 months ago

Describe the bug

I would like to be able to write try-finally blocks like so:

try {
 ...
}
finally {
  ...
}

but this is not in the syntax of Rascal.

Example usage:

void job(str label, void (void () step) block) {
   try {
     jobStart(label);
     block(() { jobStep(label, label, work=1);});
   }
   catch x: {
     throw x; // this rethrow erases the location of the original, also it doesn't add functionality to the code.
   }
   finally {
     jobEnd(label); // this is essential. I need to do this also when exceptions pop the stack.
   }
}