Comment by Akronymus

6 days ago

> In this case the surprise factor comes in, because we are used to equating finally block with cleanup and I concur that many would trip on this the first time. But if you gave this exercise some time and asked "what should happen if finally block contains control flow statements?" the reasonable answer should be "take precedence", because the behavior would be surprising/cursed otherwise.

Wouldn't the reasonable behaviour be "throw a compiler error"?

Can the compiler perform sufficiently deep static analysis to cover all possible cases? At least in Java it is by definition impossible.

  • If it's that hard to figure out what the code should do by looking at, then it's probably not a great thing to allow in the language.

  • I don't see why not. If it's in a finally block, disallow control flow. Or am I missing something?