Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 350691 - [1.7][quick fix] Precise exception not added for unhandled rethrown exception
Summary: [1.7][quick fix] Precise exception not added for unhandled rethrown exception
Status: RESOLVED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.7   Edit
Hardware: PC Windows XP
: P4 normal (vote)
Target Milestone: ---   Edit
Assignee: JDT-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-06-29 07:56 EDT by Ayushman Jain CLA
Modified: 2020-01-03 10:01 EST (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ayushman Jain CLA 2011-06-29 07:56:24 EDT
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"
Comment 1 Deepak Azad CLA 2011-07-09 08:29:49 EDT
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
	}
}
-------------------------------------------------------------------------
Comment 2 Markus Keller CLA 2011-07-12 10:15:27 EDT
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.
Comment 3 Dani Megert CLA 2011-07-20 06:55:16 EDT
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.
Comment 4 Eclipse Genie CLA 2020-01-03 09:53:33 EST
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.
Comment 5 Dani Megert CLA 2020-01-03 10:01:59 EST
No plans to work on this.