Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 365101

Summary: [xtend] validate that the same exception isn't caught multiple times
Product: [Tools] Xtend Reporter: Moritz Eysholdt <moritz.eysholdt>
Component: CoreAssignee: Project Inbox <xtend-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: christian.dietrich.opensource, sven.efftinge
Version: 2.2.0Flags: sven.efftinge: juno+
Target Milestone: ---   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

Description Moritz Eysholdt CLA 2011-11-29 11:55:40 EST
Example
----
class foo  {
	def bar() {
		try { new File("foo").canonicalPath  } catch(IOException o) {  "bar" } catch(IOException o) {  "bar" }
	}
}
----

Compiles to 

-----
public class foo {
  public String bar() {
    String _xtrycatchfinallyexpression = null;
    try {
      File _file = new File("foo");
      String _canonicalPath = _file.getCanonicalPath();
      _xtrycatchfinallyexpression = _canonicalPath;
    } catch (final IOException o) {
      _xtrycatchfinallyexpression = "bar";
    } catch (final IOException o_1) {
      _xtrycatchfinallyexpression = "bar";
    }
    return _xtrycatchfinallyexpression;
  }
}
----

The Java code doesn't compile due to the error "Unreachable catch block for IOException. It is already handled by the catch block for IOException".

I'd expect to see the same validation error in Xtend.
Comment 1 Moritz Eysholdt CLA 2011-11-29 12:03:05 EST
The same applies of a supertype of an exception is caught before its subtype:

---
try { new File("foo").canonicalPath  } catch(Exception o) {  "bar" } catch(IOException o) {  "bar" }
---
Comment 2 Christian Dietrich CLA 2016-08-24 08:29:57 EDT
Our Deady code detection catches this case menawhile