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

Bug 360785

Summary: [1.7] Quick fix to add uncaught exceptions adds already caught ones in a multi-catch block
Product: [Eclipse Project] JDT Reporter: Ayushman Jain <amj87.iitr>
Component: UIAssignee: JDT-UI-Inbox <jdt-ui-inbox>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: deepakazad
Version: 3.8   
Target Milestone: ---   
Hardware: All   
OS: All   
Whiteboard:

Description Ayushman Jain CLA 2011-10-13 05:37:26 EDT
I20110927-0800.

import java.io.FileInputStream;

public class E7Bug
{
   public static void main(final String[] args)
   {
      try (FileInputStream f = new FileInputStream("")) { // Use quick fix
          
      }
   }
}

On the mentioned line above, using quick fix to "add multi-catch clause to surrounding try" results in following erreneous code.


public class E7Bug
{
   public static void main(final String[] args)
   {
      try (FileInputStream f = new FileInputStream("")) { // Use quick fix
          
      } catch (FileNotFoundException | IOException e) {   // error here
      }
   }
}
Comment 1 Deepak Azad CLA 2011-10-13 05:50:42 EDT
This is deliberate. It is upto the user to decide what to do in this case, e.g. the user may choose to handle both exceptions separately. We can provide 'Move exception to separate catch block' quick assist as a quick fix in the produced code, see bug 352477.
Comment 2 Deepak Azad CLA 2011-10-13 05:53:11 EDT
You can also see the reasoning in bug 350713 comment 2 for a similar scenario.