Skip to content

67 Cleanup with finally ​

finally runs when the try exits, even after the return value is ready. The output order shows cleanup before control returns to the caller.

norm
Integer read() {
  try {
    printLine("open")
    return 7
  } finally {
    printLine("close")
  }
}

main() {
  printLine(read())
}

Expected output:

text
open
close
7

Try it: Change return 7 to return 9 and confirm that cleanup order stays the same.

Precise rules: Reference.

Norm 0.25