Index: trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13829)
+++ trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13830)
@@ -120,27 +120,13 @@
             }
         } catch (MalformedURLException ex) {
-            if (!GraphicsEnvironment.isHeadless()) {
-                JOptionPane.showMessageDialog(Main.parent, tr("Invalid service URL."),
-                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
-            }
-            Logging.log(Logging.LEVEL_ERROR, ex);
+            handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
         } catch (IOException ex) {
-            if (!GraphicsEnvironment.isHeadless()) {
-                JOptionPane.showMessageDialog(Main.parent, tr("Could not retrieve WMS layer list."),
-                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
-            }
-            Logging.log(Logging.LEVEL_ERROR, ex);
+            handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
         } catch (WMSGetCapabilitiesException ex) {
-            if (!GraphicsEnvironment.isHeadless()) {
-                JOptionPane.showMessageDialog(Main.parent, tr("Could not parse WMS layer list."),
-                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
-            }
-            Logging.log(Logging.LEVEL_ERROR, "Could not parse WMS layer list. Incoming data:\n"+ex.getIncomingData(), ex);
-        } catch (WMTSGetCapabilitiesException e) {
-            if (!GraphicsEnvironment.isHeadless()) {
-                JOptionPane.showMessageDialog(Main.parent, tr("Could not parse WMTS layer list."),
-                        tr("WMTS Error"), JOptionPane.ERROR_MESSAGE);
-            }
-            Logging.log(Logging.LEVEL_ERROR, "Could not parse WMTS layer list.", e);
+            handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
+                    "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
+        } catch (WMTSGetCapabilitiesException ex) {
+            handleException(ex, tr("Could not parse WMTS layer list."), tr("WMTS Error"),
+                    "Could not parse WMTS layer list.");
         }
         return null;
@@ -223,23 +209,19 @@
             return ret;
         } catch (MalformedURLException ex) {
-            if (!GraphicsEnvironment.isHeadless()) {
-                JOptionPane.showMessageDialog(Main.parent, tr("Invalid service URL."),
-                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
-            }
-            Logging.log(Logging.LEVEL_ERROR, ex);
+            handleException(ex, tr("Invalid service URL."), tr("WMS Error"), null);
         } catch (IOException ex) {
-            if (!GraphicsEnvironment.isHeadless()) {
-                JOptionPane.showMessageDialog(Main.parent, tr("Could not retrieve WMS layer list."),
-                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
-            }
-            Logging.log(Logging.LEVEL_ERROR, ex);
+            handleException(ex, tr("Could not retrieve WMS layer list."), tr("WMS Error"), null);
         } catch (WMSGetCapabilitiesException ex) {
-            if (!GraphicsEnvironment.isHeadless()) {
-                JOptionPane.showMessageDialog(Main.parent, tr("Could not parse WMS layer list."),
-                        tr("WMS Error"), JOptionPane.ERROR_MESSAGE);
-            }
-            Logging.log(Logging.LEVEL_ERROR, "Could not parse WMS layer list. Incoming data:\n"+ex.getIncomingData(), ex);
+            handleException(ex, tr("Could not parse WMS layer list."), tr("WMS Error"),
+                    "Could not parse WMS layer list. Incoming data:\n" + ex.getIncomingData());
         }
         return null;
+    }
+
+    private static void handleException(Exception ex, String uiMessage, String uiTitle, String logMessage) {
+        if (!GraphicsEnvironment.isHeadless()) {
+            JOptionPane.showMessageDialog(Main.parent, uiMessage, uiTitle, JOptionPane.ERROR_MESSAGE);
+        }
+        Logging.log(Logging.LEVEL_ERROR, logMessage, ex);
     }
 
