Community
Participate
Working Groups
BETA_JAVA7 class Foo extends Exception { } class DaughterOfFoo extends Foo { } class SonOfFoo extends Foo { } public class Snippet { void foo() { try { throw new DaughterOfFoo(); } catch (Foo e) { throw e; // try the quick fix here } } } In the above snippet, the quick fix always adds "Foo" in a throws clause or in a separate catch clause. It shoould add DaughterOfFoo instead. Even the error message says "Unhandled exception type DaughterOfFoo"
The following code looks wrong/inappropriate/confusing to me. The user wants to catch foo but add 'DaughterOfFoo' to the throws clause, which does not make much sense to me. -------------------------------------------- void foo() throws DaughterOfFoo { try { throw new DaughterOfFoo(); } catch (Foo e) { throw e; } } -------------------------------------------- Adding precise exceptions probably makes more sense in case of multi-catch. In the following instead of adding 'IOException' to throws clause we could add 'FileNotFoundException' and 'InterruptedIOException' ------------------------------------------------------------------------- void foo(int a) { try { if (a < 10) throw new FileNotFoundException(); else throw new InterruptedIOException(); } catch (FileNotFoundException | InterruptedIOException e) { throw e; // QF here } } -------------------------------------------------------------------------
I agree that this is not a common example. I don't think we should spend time on working with the precise thrown exception unless we have real use cases where this turned out to be an issue. Re comment 1, I agree that the precise type could be interesting there. But just using the declared components of the UnionType could already be enough. Anyway, we probably need new API from the compiler to get the precise type of the effectively or implicitly final catch clause variable.
I also stumbled over this while testing all possible cases but I agree that a fix would probably result in more confusing code. Maybe we should add a new compiler diagnosis that reports the cases where a more precise exception could be used inside the catch statement.
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant. -- The automated Eclipse Genie.
No plans to work on this.