<div dir="ltr">Personally, I think finally should have the suggested semantics with suppressedException. On the other hand, I understand that this would change the behavior of an existing language construct, which has no previous precedent.<br>I would argue for a similar path to switch/case when avoiding fall through. Could you not come up with an alternative syntax that is as intiutive as the original try ... finally, but has new semantics?<br><br><div>Kind regards</div><div>Kamil Sevecek</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, 17 Jul 2022 at 14:11, <<a href="mailto:some-java-user-99206970363698485155@vodafonemail.de">some-java-user-99206970363698485155@vodafonemail.de</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">> Besides the compatibility concerns of changing the operational semantics<br>
> of code that has been written for year or even decades<br>
<br>
There might be a risk of compatibility issues, but I think it is rather low. As outlined in my proposal<br>
it would mostly affect applications which inspect the suppressed exceptions in some way.<br>
I can definitely understand your concerns regarding compatibility, but I am also a bit afraid that<br>
this whole proposal is rejected due to theoretical issues which might never occur in practice.<br>
<br>
> should judge how often suppressedExceptions are looked at today. JDK 7 with try-with-resources<br>
> shipped in July 2011 so there has been ample time for developers to take advantage of the<br>
> suppressed exceptions information<br>
<br>
That is probably difficult to measure, but this would also then turn this whole discussion into<br>
a discussion about whether suppressed exceptions as a whole are useful.<br>
<br>
I have done a quick search and found the following blog posts / websites describing this issue.<br>
Some have been written before the introduction of try-with-resources, but as outlined in the<br>
proposal, it is not possible to use try-with-resources in all situations.<br>
- <a href="https://stackoverflow.com/q/25751709" rel="noreferrer" target="_blank">https://stackoverflow.com/q/25751709</a><br>
- <a href="https://stackoverflow.com/q/3779285" rel="noreferrer" target="_blank">https://stackoverflow.com/q/3779285</a><br>
- <a href="https://stackoverflow.com/q/59360652" rel="noreferrer" target="_blank">https://stackoverflow.com/q/59360652</a><br>
- <a href="https://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ311_014.htm" rel="noreferrer" target="_blank">https://www.linuxtopia.org/online_books/programming_books/thinking_in_java/TIJ311_014.htm</a><br>
- <a href="https://accu.org/journals/overload/12/62/barrettpowell_236/" rel="noreferrer" target="_blank">https://accu.org/journals/overload/12/62/barrettpowell_236/</a><br>
- <a href="https://errorprone.info/bugpattern/Finally" rel="noreferrer" target="_blank">https://errorprone.info/bugpattern/Finally</a><br>
- <a href="https://wiki.sei.cmu.edu/confluence/display/java/ERR05-J.+Do+not+let+checked+exceptions+escape+from+a+finally+block" rel="noreferrer" target="_blank">https://wiki.sei.cmu.edu/confluence/display/java/ERR05-J.+Do+not+let+checked+exceptions+escape+from+a+finally+block</a><br>
<br>
In addition to these there are the OpenJDK bug reports I mentioned in the proposal:<br>
- JDK-4988583: which is the same as this proposal<br>
- JDK-7172206: bug which is caused by this flaw and still exists today (if I see that correctly)<br>
<br>
One could now argue that this issue has been so widely discussed that developers<br>
should by now all be aware of this issue and avoid it. But I think it is quite the opposite:<br>
The current behavior is flawed and developers (who might even be aware of this issue)<br>
keep running into this issue and therefore try to warn each other about it. And any<br>
solutions or workarounds to this are pretty verbose and quite error-prone.<br>
<br>
Of course it would have been ideal if suppressed exceptions existed from the beginning<br>
and the `finally` block behaved like try-with-resources statements with regards to exception<br>
suppression. But I think with the current situation it would at least be good to improve it in<br>
the best way possible.<br>
<br>
If you and the other OpenJDK members think that this proposal is definitely not going to be<br>
included (or also independently from this decision), what do you think about reviving JDK-5108147?<br>
This would at least make manual exception suppression in `finally` blocks easier:<br>
```<br>
try {<br>
someAction();<br>
}<br>
finally (Throwable t) {<br>
try {<br>
cleanUp();<br>
}<br>
catch (Throwable t2) {<br>
if (t == null) {<br>
throw t2;<br>
} else {<br>
t.addSuppressed(t2);<br>
}<br>
}<br>
}<br>
```<br>
<br>
Kind regards<br>
<br>
</blockquote></div>