Community
Participate
Working Groups
Consider the following snippet: package a; import java.io.BufferedReader; import java.io.File; import java.io.FileReader; public class MultiCatch { public static void main(String[] args) { File file = new File(""); try (BufferedReader reader = new BufferedReader(new FileReader(file))) { System.err.println("reading..."); } catch(NullPointerException | IllegalArgumentException ex){} } } Steps: 1. once pasted there should be 2 errors about un-caught exceptions 2. quick fix the FileNotFoundException to add the exceptions to the existing list of exceptions 3. save Notice at this point your code has an error about FileNotFoundException being covered by IOException. Perhaps the quick-fix could be enhanced to detect this scenario (redundant exceptions) and avoid the 'already caught error'?
See the reasoning in bug 350713 comment 2.
I agree in general, but we should be smarter on the produced code i.e. we should offer a 'Use separate catch blocks' Quick Fix. The Quick Assist is hard to detect in the current case: one either has to select parts of the 'catch' statement or invoke Ctrl+1 twice.
(In reply to comment #2) > I agree in general, but we should be smarter on the produced code i.e. we > should offer a 'Use separate catch blocks' Quick Fix. That is Bug 352477.
(In reply to comment #3) > (In reply to comment #2) > > I agree in general, but we should be smarter on the produced code i.e. we > > should offer a 'Use separate catch blocks' Quick Fix. > That is Bug 352477. :-)