<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>OK let's try going down this route just for fun... :)<br></div><div><br></div><div>Here's a sketch of how the spec might accommodate this.<br></div><div><div><br></div><div>For any type E extending Throwble and expression or statement X, first define whether "X might throw E" as follows:</div><div><ul><li>(Precise
Special Exceptions) If E is assignable from one of:
ArithmeticException, ArrayIndexOutOfBoundsException,
ArrayStoreException, ClassCastException, AssertionError,
ExceptionInInitializerError, MatchException, NegativeArraySizeException,
NullPointerException, (others?) and X is one of those expressions which
the JLS defines to possibly throw that exception, then X might throw E.</li><li>(Imprecise Special Exceptions) If E is assignable from one
of: LinkageError (or any of its defined subclasses),
BootstrapMethodError, StackOverflowError, InternalError,
OutOfMemoryError, ThreadDeath (others?), then X might throw E.</li><li>(Checked
Exceptions) If E extends neither Error nor RuntimeException, and X is
an invocation of a method that declares it throws something assignable
to E, then X might throw Ei.</li><li>(Unchecked Exceptions) If E extends Error or RuntimeException, and X is an
invocation of a method, then X might throw E.</li></ul></div></div><div>Now consider a catch block that catches E₁ | E₂ | ... <br></div><br></div><div class="gmail_quote">Then the new rule would be:</div><div class="gmail_quote"><ul><li>For any variable V, then V is definitely [un]assigned at the start of the catch block iff the following is true for every Eᵢ: for every X in the try block that might throw Eᵢ, V is definitely [un]assigned before X.</li></ul></div><div class="gmail_quote">So most of the new complexity here seems to be in dealing with all the "special exception" cases.<br></div><div class="gmail_quote"><br></div></div></blockquote><div><br></div><div>That formalization looks very nice to me. Definitely better than the foggy idea I had in my head. And what is most appealing to me is that it actually cleanly completes the flow to the catch blocks including both DA and DU. So, given that, even this would work (not very useful, but at least shows completeness):</div><div><br></div><div>```</div><div>int x;</div>try {<br> x = 5;</div><div class="gmail_quote"> f();<br>} catch (Exception e) {<br> System.out.println(x);<br>}</div><div class="gmail_quote">```</div><div class="gmail_quote"><br></div><div class="gmail_quote">I guess the only thing missing from the definition is the finally block for completeness, and that just have to include the "exit points" of the try block (return, continue, break, and post last statement) in your "for every X" (and otherwise work like `catch(Throwable)`).</div><div class="gmail_quote"><br></div></div>