Comment by kfuse

6 days 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.

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

  • 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

  • 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).

    • I thought destructors were all noexcept now... or at the very least if you didn't noexcept, and then threw something, it just killed the process.

      Although, strictly speaking, they could have each exception also hold a reference to the prior exception that caused the excepting object to be destroyed. This forms an intrusive linked list of exceptions. Problem is, in C++ you can throw any value, so there isn't exactly any standard way for you to get the precursor exception, or any standard way for the language to tell the exception what its precursor was. In Python they could just add a field to the BaseException class that all throwables have to inherit from.

      1 reply →