<div dir="ltr"><div>OK so just to summarize the various options...</div><div><br></div><div>A. "Last assignment" - the original simple fix that only applies when the last statement is an assignment statement</div><div>B. "Simple throws" - classify all statements in two buckets "can throw" and "cannot throw"; assume any "can throw" statement can throw anything type of exception<br></div><div>C. "Complex throws, any checked" - classify all statements by which exception types they can throw; assume methods can throw any unchecked or checked exceptions</div><div>D. "Complex throws, declared checked" - classify all statements by which
exception types they can throw; assume methods can throw any unchecked or declared
checked exceptions<br></div><div><br></div><div>And of course "do nothing" is always the default option :)<br></div><div><br></div><div>I'd also like to hear other folks' opinions.</div><div><br></div><div>-Archie<br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Jul 16, 2024 at 12:35 PM Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com">attila.kelemen85@gmail.com</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"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div style="margin-left:40px"><span style="font-family:monospace">final int x;</span></div><div style="margin-left:40px"><span style="font-family:monospace">int neg_x = 0;<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">try {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> x = method();</span></div><div style="margin-left:40px"><span style="font-family:monospace"> neg_x = -x; // "trailing trivial stuff"<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">} catch (Exception e) {</span></div><div style="margin-left:40px"><span style="font-family:monospace"> x = 0;<br></span></div><div style="margin-left:40px"><span style="font-family:monospace">}</span><br></div><div><br></div><div><div>At this point, is it even worth it to do this more complicated analysis? It's not much gain for all that work when compared to the original simpler fix.</div></div></div></div></blockquote><div><br></div><div>If it is worth it or not of course is a question of preference. To my mind, it is much cleaner than the special rule for "last statement is assignment". I think the only way to decide if it is worth it or not is if many more people would voice their opinion. To me it just feels too special to talk about the "last assignment" and what is that last statement.</div><div><br></div><div>To me actually the most strange property of the "last assignment" rule is that an "if-else" chain would not work. Not so much that I want to make one more trivial assignment. But I think if the rule wants to allow the "if-else" chain then it is probably easier to allow your last example as well.</div><div><br></div><div>As for the exceptions: There can be other middle grounds here to simplify stuff. I originally thought that a statement or expression can either throw an exception or not, and if it can, we assume that it may throw literally anything (so, `x = a.b;` is assumed to potentially throw an `IOException`). That would make the rules a lot simpler, yet would be still less surprising in my opinion.</div></div></div>
</blockquote></div><br clear="all"><br><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature">Archie L. Cobbs<br></div>