top | item 45870558

(no title)

kfuse | 3 months ago

That's not just Java and there is nothing really cursed about it: throwing in a finally block is the most common example. Jump statements are no different, you can't just ignore them when they override the return or throw statements.

discuss

order

Maxatar|3 months ago

It is just Java as far as I can tell. Other languages with a finally don't allow for explicitly exiting the finally block.

maxdamantus|3 months ago

And JavaScript .. And Python (though as sibling posts have mentioned it looks like they're intending to make a breaking change to remove it).

EDIT: actually, the PEP points out that they intend for it to only be a warning in CPython, to avoid the breaking change

ajb|3 months ago

Modula-3 has it despite not having a continue statement:

https://www.cs.purdue.edu/homes/hosking/m3/reference/exit.ht...

But there, it's more comprensible because in order to define the interaction of return (and exit) with exceptions, they define return, and exit, to be exceptions. So then it's more obvious why return can be "caught".

o11c|3 months ago

Notably, C++ and similar languages don't support lexical `finally` at all, instead relying on destructors, which are a function and obviously cannot affect the control flow of their caller ...

except by throwing exceptions, which is a different problem that there's no "good" solution to (during unwinding, that is).

MangoToupe|3 months ago

> override the return

How is this not cursed