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

Bug 365095

Summary: [xtend] Always produce working Java code for catch clauses
Product: [Modeling] TMF Reporter: Moritz Eysholdt <moritz.eysholdt>
Component: XtextAssignee: Project Inbox <tmf.xtext-inbox>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: Holger.Schill, sven.efftinge
Version: unspecifiedFlags: sven.efftinge: juno+
Target Milestone: M4   
Hardware: Macintosh   
OS: Mac OS X   
Whiteboard:

Description Moritz Eysholdt CLA 2011-11-29 11:36:13 EST
Example:


-----
class foo  {
	def bar() {
		try { "foo "} catch(IOException o) { "bar" }
	}
}
-----

this compiles to 

-----
public class foo {
  public String bar() {
    String _xtrycatchfinallyexpression = null;
    try {
      _xtrycatchfinallyexpression = "foo ";
    } catch (final IOException o) {
      _xtrycatchfinallyexpression = "bar";
    }
    return _xtrycatchfinallyexpression;
  }
}
-----

The Java code fails to compile with the message "Unreachable catch block for IOException. This exception is never thrown from the try statement body".

I'd expect to see the same validation message in Xtend.
Comment 1 Holger Schill CLA 2011-12-01 09:58:12 EST
Until https://bugs.eclipse.org/bugs/show_bug.cgi?id=365320 is not fixed we will not have the possibility to fix this issue because we would raise false errors in most of the cases.
Comment 2 Sven Efftinge CLA 2011-12-01 10:12:47 EST
We shouldn't have this validation but make sure that working Java code is produced.

something like this :

catch (Throwable t) {
   // translate catch clauses to instanceof
   if (t instance of IOException) {
       // handle code ...
   } ...
   } else {
       sneakyThrow
   }
}
Comment 3 Sven Efftinge CLA 2011-12-01 11:58:14 EST
pushed to master
Comment 4 Karsten Thoms CLA 2017-09-19 17:33:58 EDT
Closing all bugs that were set to RESOLVED before Neon.0
Comment 5 Karsten Thoms CLA 2017-09-19 17:45:05 EDT
Closing all bugs that were set to RESOLVED before Neon.0