Bug 63114 - Nested Exceptions are not picked up.
Summary: Nested Exceptions are not picked up.
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.1.2   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.0 M9   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-05-19 16:42 EDT by Austin Tam CLA
Modified: 2004-05-19 18:28 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Austin Tam CLA 2004-05-19 16:42:46 EDT
Given the following class:

public class A {
	public static String a() {
		try{
		     
		}
		catch (Exception e) {
			B.b();
                        //this will have the same effect:
			//throw new Exception();
		}
		finally {
			return "";		
		}
		
	}
}

class B {
	public static void b() throws Exception {	
	}
}





Eclipse incremental compilter will not flag the possible Exception that is 
thrown by B.b();
The key is in the nested Exception.

If the return is taken out of the finally clause and put at the end of the 
method a(); then eclipse will pick up the error.

Also reproducible in 2.1.3
Comment 1 Philipe Mulet CLA 2004-05-19 18:12:30 EDT
If you remove the return statement from finally block, you'll observe that the 
exception analysis is working as expected.

The thrown exception in catch block is superceded by the return in finally 
block. Any such exception is intercepted by the finally block, and since it 
doesn't complete normally, it gets lost.

This behavior is mandated by the JLS analysis for code reachability, and other 
compilers agree with us. 

FYI - we provide an optional warning to diagnose such nasty finally blocks, 
which do not complete normally.

Quizz: what does the following code return ?
try {
  return 1;
} finally {
  return 2;
}
Comment 2 Philipe Mulet CLA 2004-05-19 18:13:12 EDT
Answer: 2




Closing as invalid.
Comment 3 Austin Tam CLA 2004-05-19 18:28:36 EDT
Yes, I think you're right.
Thanks