Community
Participate
Working Groups
I20050527-1300 Extracting code that can return a value and ends with throwing an exception results in a new method with no return type - and therefore compile errors. No other errors or exceptions. Before: class Foo { int bar(int bar) { if (bar > 0) return bar - 1; throw new IllegalArgumentException(); } } After: class Foo { int bar(int bar) { foo(bar); } private void foo(int bar) { if (bar > 0) return bar - 1; throw new IllegalArgumentException(); } } Swapping the return and the throw statements works. Before: class Foo { int bar(int bar) { if (bar > 0) throw new IllegalArgumentException(); return bar - 1; } } After: class Foo { int bar(int bar) { return foo(bar); } private int foo(int bar) { if (bar > 0) throw new IllegalArgumentException(); return bar - 1; } }
Created attachment 140808 [details] patch + testcase Currently the two "branches" return a Partial return (if without else) and a throw. As a combination of this
Too early to submit :| In combination (throw+partial return) always returns a value or throws a exception we always have a return value. The return kind table was adjusted accordingly.
Thanks, released to HEAD and fixed the tests (there was just 1 test, without corresponding 'out', and the test was only for the case that already worked).
Verified for 3.6 M1 using I20090803-1800