Index: trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13387)
+++ trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 13388)
@@ -40,4 +40,5 @@
 import org.openstreetmap.josm.tools.ImageProvider;
 import org.openstreetmap.josm.tools.Logging;
+import org.openstreetmap.josm.tools.bugreport.ReportedException;
 
 /**
@@ -136,17 +137,21 @@
     public void actionPerformed(ActionEvent e) {
         if (!isEnabled()) return;
+        ImageryLayer layer = null;
         try {
             final ImageryInfo infoToAdd = convertImagery(info);
             if (infoToAdd != null) {
-                getLayerManager().addLayer(ImageryLayer.create(infoToAdd));
+                layer = ImageryLayer.create(infoToAdd);
+                getLayerManager().addLayer(layer);
                 AlignImageryPanel.addNagPanelIfNeeded(infoToAdd);
             }
-        } catch (IllegalArgumentException ex) {
+        } catch (IllegalArgumentException | ReportedException ex) {
             if (ex.getMessage() == null || ex.getMessage().isEmpty() || GraphicsEnvironment.isHeadless()) {
                 throw ex;
             } else {
-                JOptionPane.showMessageDialog(Main.parent,
-                        ex.getMessage(), tr("Error"),
-                        JOptionPane.ERROR_MESSAGE);
+                Logging.error(ex);
+                JOptionPane.showMessageDialog(Main.parent, ex.getMessage(), tr("Error"), JOptionPane.ERROR_MESSAGE);
+                if (layer != null) {
+                    getLayerManager().removeLayer(layer);
+                }
             }
         }
Index: trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java
===================================================================
--- trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 13387)
+++ trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java	(revision 13388)
@@ -147,4 +147,9 @@
             identifier = builder.identifier;
         }
+
+        @Override
+        public String toString() {
+            return "TileMatrixSet [crs=" + crs + ", identifier=" + identifier + ']';
+        }
     }
 
@@ -188,4 +193,10 @@
         public String getUserTitle() {
             return title != null ? title : identifier;
+        }
+
+        @Override
+        public String toString() {
+            return "Layer [identifier=" + identifier + ", title=" + title + ", tileMatrixSet="
+                    + tileMatrixSet + ", baseUrl=" + baseUrl + ", style=" + style + ']';
         }
     }
@@ -683,5 +694,6 @@
                 }
                 if (this.currentLayer == null)
-                    return;
+                    throw new IllegalArgumentException(
+                            layers.stream().map(l -> l.tileMatrixSet).collect(Collectors.toList()).toString());
             } // else: keep currentLayer and tileProjection as is
         }
