Changeset 7004 in josm


Ignore:
Timestamp:
2014-04-26T15:28:16+02:00 (10 years ago)
Author:
Don-vip
Message:

see #8465 - use multi-catch where applicable

Location:
trunk/src/org/openstreetmap/josm
Files:
31 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/SessionLoadAction.java

    r6992 r7004  
    3232
    3333/**
    34  * Loads a JOSM session
     34 * Loads a JOSM session.
    3535 * @since 4668
    3636 */
     
    174174                }
    175175            } catch (IllegalDataException e) {
    176                 Main.error(e);
    177                 HelpAwareOptionPane.showMessageDialogInEDT(
    178                         Main.parent,
    179                         tr("<html>Could not load session file ''{0}''.<br>Error is:<br>{1}</html>", uri != null ? uri : file.getName(), e.getMessage()),
    180                         tr("Data Error"),
    181                         JOptionPane.ERROR_MESSAGE,
    182                         null
    183                         );
    184                 cancel();
     176                handleException(tr("Data Error"), e);
    185177            } catch (IOException e) {
    186                 Main.error(e);
    187                 HelpAwareOptionPane.showMessageDialogInEDT(
    188                         Main.parent,
    189                         tr("<html>Could not load session file ''{0}''.<br>Error is:<br>{1}</html>", uri != null ? uri : file.getName(), e.getMessage()),
    190                         tr("IO Error"),
    191                         JOptionPane.ERROR_MESSAGE,
    192                         null
    193                         );
    194                 cancel();
     178                handleException(tr("IO Error"), e);
    195179            } catch (RuntimeException e) {
    196180                cancel();
     
    201185            }
    202186        }
     187       
     188        private void handleException(String dialogTitle, Exception e) {
     189            Main.error(e);
     190            HelpAwareOptionPane.showMessageDialogInEDT(
     191                    Main.parent,
     192                    tr("<html>Could not load session file ''{0}''.<br>Error is:<br>{1}</html>", uri != null ? uri : file.getName(), e.getMessage()),
     193                    dialogTitle,
     194                    JOptionPane.ERROR_MESSAGE,
     195                    null
     196                    );
     197            cancel();
     198        }
    203199    }
    204200}
    205 
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadSessionTask.java

    r6643 r7004  
    55
    66import java.io.IOException;
    7 import java.net.MalformedURLException;
    87import java.net.URISyntaxException;
    98import java.net.URL;
     
    5453                loader = new Loader(Utils.openURL(u), u.toURI(), url.endsWith(".joz"));
    5554                return Main.worker.submit(loader);
    56             } catch (URISyntaxException e) {
    57                 Main.error(e);
    58             } catch (MalformedURLException e) {
    59                 Main.error(e);
    60             } catch (IOException e) {
     55            } catch (URISyntaxException | IOException e) {
    6156                Main.error(e);
    6257            }
  • trunk/src/org/openstreetmap/josm/data/Preferences.java

    r6990 r7004  
    11671167        try {
    11681168            structPrototype = klass.newInstance();
    1169         } catch (InstantiationException ex) {
    1170             throw new RuntimeException(ex);
    1171         } catch (IllegalAccessException ex) {
     1169        } catch (InstantiationException | IllegalAccessException ex) {
    11721170            throw new RuntimeException(ex);
    11731171        }
     
    11871185                    }
    11881186                }
    1189             } catch (IllegalArgumentException ex) {
    1190                 throw new RuntimeException(ex);
    1191             } catch (IllegalAccessException ex) {
     1187            } catch (IllegalArgumentException | IllegalAccessException ex) {
    11921188                throw new RuntimeException(ex);
    11931189            }
     
    12001196        try {
    12011197            struct = klass.newInstance();
    1202         } catch (InstantiationException ex) {
    1203             throw new RuntimeException(ex);
    1204         } catch (IllegalAccessException ex) {
     1198        } catch (InstantiationException | IllegalAccessException ex) {
    12051199            throw new RuntimeException(ex);
    12061200        }
  • trunk/src/org/openstreetmap/josm/data/ServerSidePreferences.java

    r6995 r7004  
    175175        try {
    176176            fromXML(in);
    177         } catch (RuntimeException e) {
    178             Main.error(e);
    179         } catch (XMLStreamException e) {
     177        } catch (RuntimeException | XMLStreamException e) {
    180178            Main.error(e);
    181179        }
  • trunk/src/org/openstreetmap/josm/data/osm/visitor/paint/MapRendererFactory.java

    r6883 r7004  
    268268            Constructor<?> c = activeRenderer.getConstructor(new Class<?>[]{Graphics2D.class, NavigatableComponent.class, boolean.class});
    269269            return AbstractMapRenderer.class.cast(c.newInstance(g, viewport, isInactiveMode));
    270         } catch(NoSuchMethodException e){
    271             throw new MapRendererFactoryException(e);
    272         } catch (IllegalArgumentException e) {
    273             throw new MapRendererFactoryException(e);
    274         } catch (InstantiationException e) {
    275             throw new MapRendererFactoryException(e);
    276         } catch (IllegalAccessException e) {
     270        } catch(NoSuchMethodException | IllegalArgumentException | InstantiationException | IllegalAccessException e){
    277271            throw new MapRendererFactoryException(e);
    278272        } catch (InvocationTargetException e) {
  • trunk/src/org/openstreetmap/josm/data/projection/proj/ClassProjFactory.java

    r5227 r7004  
    1818        try {
    1919            proj = projClass.newInstance();
    20         } catch (InstantiationException e) {
    21             throw new RuntimeException(e);
    22         } catch (IllegalAccessException e) {
     20        } catch (InstantiationException | IllegalAccessException e) {
    2321            throw new RuntimeException(e);
    2422        }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OpeningHourTest.java

    r6986 r7004  
    209209                errors.add(new OpeningHoursTestError(tr("opening_hours value can be prettified"), Severity.OTHER, prettifiedValue));
    210210            }
    211         } catch (ScriptException ex) {
    212             Main.error(ex);
    213         } catch (NoSuchMethodException ex) {
     211        } catch (ScriptException | NoSuchMethodException ex) {
    214212            Main.error(ex);
    215213        }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java

    r6823 r7004  
    714714                } catch (IllegalStateException e) {
    715715                    return tr("Illegal expression ''{0}''", exp);
    716                 }
    717                 catch (PatternSyntaxException e) {
     716                } catch (PatternSyntaxException e) {
    718717                    return tr("Illegal regular expression ''{0}''", exp);
    719718                }
  • trunk/src/org/openstreetmap/josm/gui/JosmUserIdentityManager.java

    r6990 r7004  
    217217            UserInfo info = new OsmServerUserInfoReader().fetchUserInfo(NullProgressMonitor.INSTANCE);
    218218            setFullyIdentified(info.getDisplayName(), info);
    219         } catch (IllegalArgumentException e) {
    220             Main.error(e);
    221         } catch (OsmTransferException e) {
     219        } catch (IllegalArgumentException | OsmTransferException e) {
    222220            Main.error(e);
    223221        }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/ValidatorDialog.java

    r6529 r7004  
    638638                    }
    639639                });
    640             } catch(InterruptedException e) {
     640            } catch(InterruptedException | InvocationTargetException e) {
    641641                // FIXME: signature of realRun should have a generic checked exception we
    642642                // could throw here
    643643                throw new RuntimeException(e);
    644             } catch(InvocationTargetException e) {
    645                 throw new RuntimeException(e);
    646644            } finally {
    647645                monitor.finishTask();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentDownloadTask.java

    r6830 r7004  
    196196                return;
    197197            lastException = e;
    198         } catch(RuntimeException e) {
    199             throw e;
    200198        }
    201199    }
  • trunk/src/org/openstreetmap/josm/gui/layer/geoimage/GeoImageLayer.java

    r6792 r7004  
    552552            dirExif = metadata.getDirectory(ExifIFD0Directory.class);
    553553            dirGps = metadata.getDirectory(GpsDirectory.class);
    554         } catch (CompoundException p) {
    555             e.setExifCoor(null);
    556             e.setPos(null);
    557             return;
    558         } catch (IOException p) {
     554        } catch (CompoundException | IOException p) {
    559555            e.setExifCoor(null);
    560556            e.setPos(null);
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r6927 r7004  
    8383            parameterFunctions.add(Math.class.getMethod("tan", double.class));
    8484            parameterFunctions.add(Math.class.getMethod("tanh", double.class));
    85         } catch (NoSuchMethodException ex) {
    86             throw new RuntimeException(ex);
    87         } catch (SecurityException ex) {
     85        } catch (NoSuchMethodException | SecurityException ex) {
    8886            throw new RuntimeException(ex);
    8987        }
     
    752750            try {
    753751                result = m.invoke(FUNCTIONS_INSTANCE, convertedArgs);
    754             } catch (IllegalAccessException ex) {
    755                 throw new RuntimeException(ex);
    756             } catch (IllegalArgumentException ex) {
     752            } catch (IllegalAccessException | IllegalArgumentException ex) {
    757753                throw new RuntimeException(ex);
    758754            } catch (InvocationTargetException ex) {
     
    815811            try {
    816812                result = m.invoke(null, convertedArgs);
    817             } catch (IllegalAccessException ex) {
    818                 throw new RuntimeException(ex);
    819             } catch (IllegalArgumentException ex) {
     813            } catch (IllegalAccessException | IllegalArgumentException ex) {
    820814                throw new RuntimeException(ex);
    821815            } catch (InvocationTargetException ex) {
  • trunk/src/org/openstreetmap/josm/gui/oauth/OsmOAuthAuthorizationClient.java

    r6995 r7004  
    2626import oauth.signpost.OAuthProvider;
    2727import oauth.signpost.basic.DefaultOAuthProvider;
    28 import oauth.signpost.exception.OAuthCommunicationException;
    2928import oauth.signpost.exception.OAuthException;
    3029
     
    110109                    con.disconnect();
    111110                }
    112             } catch (NoSuchFieldException e) {
    113                 Main.error(e);
    114                 Main.warn(tr("Failed to cancel running OAuth operation"));
    115             } catch (SecurityException e) {
    116                 Main.error(e);
    117                 Main.warn(tr("Failed to cancel running OAuth operation"));
    118             } catch (IllegalAccessException e) {
     111            } catch (NoSuchFieldException | SecurityException | IllegalAccessException e) {
    119112                Main.error(e);
    120113                Main.warn(tr("Failed to cancel running OAuth operation"));
     
    146139            provider.retrieveRequestToken(consumer, "");
    147140            return OAuthToken.createToken(consumer);
    148         } catch(OAuthCommunicationException e){
    149             if (canceled)
    150                 throw new OsmTransferCanceledException(e);
    151             throw new OsmOAuthAuthorizationException(e);
    152141        } catch(OAuthException e){
    153142            if (canceled)
     
    180169            provider.retrieveAccessToken(consumer, null);
    181170            return OAuthToken.createToken(consumer);
    182         } catch(OAuthCommunicationException e){
    183             if (canceled)
    184                 throw new OsmTransferCanceledException(e);
    185             throw new OsmOAuthAuthorizationException(e);
    186171        } catch(OAuthException e){
    187172            if (canceled)
     
    441426            connection.setDoOutput(false);
    442427            connection.connect();
    443         } catch(MalformedURLException e) {
    444             throw new OsmOAuthAuthorizationException(e);
    445428        } catch(IOException e) {
    446429            throw new OsmOAuthAuthorizationException(e);
     
    504487            if (retCode != HttpURLConnection.HTTP_OK)
    505488                throw new OsmOAuthAuthorizationException(tr("Failed to authorize OAuth request  ''{0}''", requestToken.getKey()));
    506         } catch(MalformedURLException e) {
    507             throw new OsmOAuthAuthorizationException(e);
    508489        } catch(IOException e) {
    509490            throw new OsmOAuthAuthorizationException(e);
  • trunk/src/org/openstreetmap/josm/gui/oauth/TestAccessTokenTask.java

    r6906 r7004  
    77import java.io.IOException;
    88import java.net.HttpURLConnection;
    9 import java.net.MalformedURLException;
    109import java.net.URL;
    1110
     
    123122            Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(connection.getInputStream());
    124123            return OsmServerUserInfoReader.buildFromXML(d);
    125         } catch(SAXException e) {
     124        } catch(SAXException | ParserConfigurationException e) {
    126125            throw new XmlParsingException(e);
    127         } catch(ParserConfigurationException e){
    128             throw new XmlParsingException(e);
    129         } catch(MalformedURLException e) {
    130             throw new OsmTransferException(e);
    131         } catch(IOException e){
     126        } catch(IOException e) {
    132127            throw new OsmTransferException(e);
    133128        } catch(OAuthException e) {
  • trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java

    r7001 r7004  
    372372                    }
    373373                });
    374             } catch (InterruptedException e) {
    375                 Main.error(e);
    376             } catch (InvocationTargetException e) {
     374            } catch (InterruptedException | InvocationTargetException e) {
    377375                Main.error(e);
    378376            }
  • trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java

    r6990 r7004  
    374374                }
    375375                model.fireTableDataChanged();
    376             } catch (PatternSyntaxException ex) {
     376            } catch (PatternSyntaxException | ClassCastException ex) {
    377377                Main.warn(ex);
    378             } catch (ClassCastException ex2) {
    379                 Main.warn(ex2);
    380378            }
    381379        }
  • trunk/src/org/openstreetmap/josm/gui/util/GuiHelper.java

    r6920 r7004  
    8282            try {
    8383                SwingUtilities.invokeAndWait(task);
    84             } catch (InterruptedException e) {
     84            } catch (InterruptedException | InvocationTargetException e) {
    8585                Main.error(e);
    86             } catch (InvocationTargetException e) {
    87                 Main.error(e);
    88             }
    89         }
    90     }
    91 
    92     /**
    93      * returns true if the user wants to cancel, false if they
    94      * want to continue
     86            }
     87        }
     88    }
     89
     90    /**
     91     * @return true if the user wants to cancel, false if they want to continue
    9592     */
    9693    public static final boolean warnUser(String title, String content, ImageIcon baseActionIcon, String continueToolTip) {
  • trunk/src/org/openstreetmap/josm/io/DiffResultProcessor.java

    r6906 r7004  
    8585            InputSource inputSource = new InputSource(new StringReader(diffUploadResponse));
    8686            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser());
    87         } catch(IOException e) {
    88             throw new XmlParsingException(e);
    89         } catch(ParserConfigurationException e) {
    90             throw new XmlParsingException(e);
    9187        } catch(XmlParsingException e) {
    9288            throw e;
    93         } catch(SAXException e) {
     89        } catch(IOException | ParserConfigurationException | SAXException e) {
    9490            throw new XmlParsingException(e);
    9591        } finally {
  • trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java

    r6830 r7004  
    356356                    merge(result.dataSet);
    357357                }
    358             } catch (InterruptedException e) {
    359                 Main.error(e);
    360             } catch (ExecutionException e) {
     358            } catch (InterruptedException | ExecutionException e) {
    361359                Main.error(e);
    362360            }
  • trunk/src/org/openstreetmap/josm/io/OsmApi.java

    r6995 r7004  
    2020import java.net.SocketTimeoutException;
    2121import java.net.URL;
    22 import java.net.UnknownHostException;
    2322import java.util.Collection;
    2423import java.util.Collections;
     
    716715                    throw new OsmApiException(retCode, errorHeader, errorBody);
    717716                }
    718             } catch (UnknownHostException e) {
    719                 throw new OsmTransferException(e);
    720             } catch (SocketTimeoutException e) {
    721                 if (retries-- > 0) {
    722                     continue;
    723                 }
    724                 throw new OsmTransferException(e);
    725             } catch (ConnectException e) {
     717            } catch (SocketTimeoutException | ConnectException e) {
    726718                if (retries-- > 0) {
    727719                    continue;
     
    730722            } catch(IOException e) {
    731723                throw new OsmTransferException(e);
    732             } catch(OsmTransferCanceledException e) {
    733                 throw e;
    734724            } catch(OsmTransferException e) {
    735725                throw e;
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java

    r6906 r7004  
    142142        } catch(XmlParsingException e) {
    143143            throw e;
    144         } catch (ParserConfigurationException e) {
    145             throw new XmlParsingException(e);
    146         } catch(SAXException e) {
    147             throw new XmlParsingException(e);
    148         } catch(IOException e) {
     144        } catch (ParserConfigurationException | SAXException | IOException e) {
    149145            throw new XmlParsingException(e);
    150146        } finally {
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetParser.java

    r6906 r7004  
    223223            SAXParserFactory.newInstance().newSAXParser().parse(inputSource, parser.new Parser());
    224224            return parser.getChangesets();
    225         } catch(ParserConfigurationException e) {
    226             throw new IllegalDataException(e.getMessage(), e);
    227         } catch(SAXException e) {
     225        } catch(ParserConfigurationException | SAXException e) {
    228226            throw new IllegalDataException(e.getMessage(), e);
    229227        } catch(Exception e) {
  • trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControlHttpsServer.java

    r6941 r7004  
    8888                    initOK = true;
    8989                }
    90             } catch (KeyStoreException e) {
    91                 Main.error(e);
    92             } catch (NoSuchAlgorithmException e) {
    93                 Main.error(e);
    94             } catch (CertificateException e) {
    95                 Main.error(e);
    96             } catch (IOException e) {
    97                 Main.error(e);
    98             } catch (UnrecoverableKeyException e) {
    99                 Main.error(e);
    100             } catch (KeyManagementException e) {
     90            } catch (KeyStoreException | NoSuchAlgorithmException | CertificateException |
     91                    IOException | UnrecoverableKeyException | KeyManagementException e) {
    10192                Main.error(e);
    10293            }
  • trunk/src/org/openstreetmap/josm/io/session/SessionReader.java

    r6992 r7004  
    7777        try {
    7878            importer = importerClass.newInstance();
    79         } catch (InstantiationException e) {
    80             throw new RuntimeException(e);
    81         } catch (IllegalAccessException e) {
     79        } catch (InstantiationException | IllegalAccessException e) {
    8280            throw new RuntimeException(e);
    8381        }
     
    457455                try {
    458456                    layer = imp.load(e, support, progressMonitor.createSubTaskMonitor(1, false));
    459                 } catch (IllegalDataException ex) {
    460                     exception = ex;
    461                 } catch (IOException ex) {
     457                } catch (IllegalDataException | IOException ex) {
    462458                    exception = ex;
    463459                }
     
    542538                    }
    543539                });
    544             } catch (InvocationTargetException ex) {
    545                 throw new RuntimeException(ex);
    546             } catch (InterruptedException ex) {
     540            } catch (InvocationTargetException | InterruptedException ex) {
    547541                throw new RuntimeException(ex);
    548542            }
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r6990 r7004  
    11671167            GuiHelper.runInEDT(task);
    11681168            return task.get();
    1169         } catch (InterruptedException e) {
    1170             Main.warn(e);
    1171         } catch (ExecutionException e) {
     1169        } catch (InterruptedException | ExecutionException e) {
    11721170            Main.warn(e);
    11731171        }
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r6890 r7004  
    320320            Object plugin = c.newInstance(this);
    321321            return new PluginProxy(plugin, this);
    322         } catch(NoSuchMethodException e) {
    323             throw new PluginException(name, e);
    324         } catch(IllegalAccessException e) {
    325             throw new PluginException(name, e);
    326         } catch (InstantiationException e) {
    327             throw new PluginException(name, e);
    328         } catch(InvocationTargetException e) {
     322        } catch(NoSuchMethodException | IllegalAccessException | InstantiationException | InvocationTargetException e) {
    329323            throw new PluginException(name, e);
    330324        }
     
    343337        try {
    344338            return Class.forName(className, true, classLoader);
    345         } catch (ClassNotFoundException e) {
    346             throw new PluginException(name, e);
    347         } catch (ClassCastException e) {
     339        } catch (ClassNotFoundException | ClassCastException e) {
    348340            throw new PluginException(name, e);
    349341        }
  • trunk/src/org/openstreetmap/josm/tools/ExifReader.java

    r6830 r7004  
    8787            final Directory dir = metadata.getDirectory(ExifIFD0Directory.class);
    8888            return dir.getInt(ExifIFD0Directory.TAG_ORIENTATION);
    89         } catch (JpegProcessingException e) {
    90             Main.error(e);
    91         } catch (MetadataException e) {
    92             Main.error(e);
    93         } catch (IOException e) {
     89        } catch (JpegProcessingException | MetadataException | IOException e) {
    9490            Main.error(e);
    9591        }
  • trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java

    r6920 r7004  
    2828                url = URLDecoder.decode(url, "UTF-8");
    2929            }
    30         } catch (UnsupportedEncodingException x) {
    31             Main.error(x);
    32         } catch (IllegalArgumentException x) {
     30        } catch (UnsupportedEncodingException | IllegalArgumentException x) {
    3331            Main.error(x);
    3432        }
     
    7270                        z == null ? 18 : Integer.parseInt(z));
    7371            }
    74         } catch (NumberFormatException x) {
    75             Main.error(x);
    76         } catch (NullPointerException x) {
    77             Main.error(x);
    78         } catch (ArrayIndexOutOfBoundsException x) {
     72        } catch (NumberFormatException | NullPointerException | ArrayIndexOutOfBoundsException x) {
    7973            Main.error(x);
    8074        }
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java

    r7001 r7004  
    5757                }
    5858                return;
    59             } catch (IOException e) {
    60                 Main.warn(e);
    61             } catch (URISyntaxException e) {
     59            } catch (IOException | URISyntaxException e) {
    6260                Main.warn(e);
    6361            }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r7003 r7004  
    461461                return (String) t.getTransferData(DataFlavor.stringFlavor);
    462462            }
    463         } catch (UnsupportedFlavorException ex) {
    464             Main.error(ex);
    465             return null;
    466         } catch (IOException ex) {
     463        } catch (UnsupportedFlavorException | IOException ex) {
    467464            Main.error(ex);
    468465            return null;
Note: See TracChangeset for help on using the changeset viewer.