Index: trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java
===================================================================
--- trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 4530)
+++ trunk/src/org/openstreetmap/josm/actions/AddImageryLayerAction.java	(revision 4531)
@@ -5,4 +5,6 @@
 
 import java.awt.event.ActionEvent;
+
+import javax.swing.JOptionPane;
 
 import org.openstreetmap.josm.Main;
@@ -25,5 +27,15 @@
     public void actionPerformed(ActionEvent e) {
         if (!isEnabled()) return;
-        Main.main.addLayer(ImageryLayer.create(info));
+        try {
+            Main.main.addLayer(ImageryLayer.create(info));
+        } catch (IllegalArgumentException ex) {
+            if (ex.getMessage() == null || ex.getMessage().isEmpty()) {
+                throw ex;
+            } else {
+                JOptionPane.showMessageDialog(Main.parent,
+                        ex.getMessage(), tr("Error"),
+                        JOptionPane.ERROR_MESSAGE);
+            }
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java	(revision 4530)
+++ trunk/src/org/openstreetmap/josm/gui/bbox/SlippyMapBBoxChooser.java	(revision 4531)
@@ -1,4 +1,6 @@
 // License: GPL. See LICENSE file for details.
 package org.openstreetmap.josm.gui.bbox;
+
+import static org.openstreetmap.josm.tools.I18n.tr;
 
 import java.awt.Color;
@@ -18,4 +20,6 @@
 import java.util.Vector;
 import java.util.concurrent.CopyOnWriteArrayList;
+
+import javax.swing.JOptionPane;
 
 import org.openstreetmap.gui.jmapviewer.Coordinate;
@@ -37,5 +41,4 @@
 import org.openstreetmap.josm.data.preferences.StringProperty;
 import org.openstreetmap.josm.gui.layer.TMSLayer;
-import org.openstreetmap.josm.tools.OpenBrowser;
 
 public class SlippyMapBBoxChooser extends JMapViewer implements BBoxChooser{
@@ -114,7 +117,15 @@
                     continue;
                 }
-                TileSource source = TMSLayer.getTileSource(info);
-                if (source != null) {
-                    sources.add(source);
+                try {
+                    TileSource source = TMSLayer.getTileSource(info);
+                    if (source != null) {
+                        sources.add(source);
+                    }
+                } catch (IllegalArgumentException ex) {
+                    if (ex.getMessage() != null && !ex.getMessage().isEmpty()) {
+                        JOptionPane.showMessageDialog(Main.parent,
+                                ex.getMessage(), tr("Warning"),
+                                JOptionPane.WARNING_MESSAGE);
+                    }
                 }
             }
Index: trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 4530)
+++ trunk/src/org/openstreetmap/josm/gui/layer/TMSLayer.java	(revision 4531)
@@ -24,4 +24,6 @@
 import java.util.List;
 import java.util.Map;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 
 import javax.swing.AbstractAction;
@@ -222,6 +224,7 @@
     }
 
-    public static TileSource getTileSource(ImageryInfo info) {
+    public static TileSource getTileSource(ImageryInfo info) throws IllegalArgumentException {
         if (info.getImageryType() == ImageryType.TMS) {
+            checkUrl(info.getUrl());
             TMSTileSource t = new TemplatedTMSTileSource(info.getName(), info.getUrl(), info.getMinZoom(), info.getMaxZoom());
             info.setAttribution(t);
@@ -232,4 +235,24 @@
             return new ScanexTileSource(info.getUrl());
         return null;
+    }
+    
+    public static void checkUrl(String url) throws IllegalArgumentException {
+        if (url == null) {
+            throw new IllegalArgumentException();
+        } else {
+            Matcher m = Pattern.compile("\\{[^}]*\\}").matcher(url);
+            while (m.find()) {
+                boolean isSupportedPattern = false;
+                for (String pattern : TemplatedTMSTileSource.ALL_PATTERNS) {
+                    if (m.group().matches(pattern)) {
+                        isSupportedPattern = true;
+                        break;
+                    }
+                }
+                if (!isSupportedPattern) {
+                    throw new IllegalArgumentException(tr("{0} is not a valid TMS argument. Please check this server URL:\n{1}", m.group(), url));
+                }
+            }
+        }
     }
 
Index: trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
===================================================================
--- trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java	(revision 4530)
+++ trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java	(revision 4531)
@@ -70,4 +70,5 @@
 import org.openstreetmap.josm.data.imagery.ImageryInfo;
 import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryBounds;
+import org.openstreetmap.josm.data.imagery.ImageryInfo.ImageryType;
 import org.openstreetmap.josm.data.imagery.ImageryLayerInfo;
 import org.openstreetmap.josm.data.imagery.OffsetBookmark;
@@ -626,5 +627,19 @@
                         JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
                 if (answer == JOptionPane.OK_OPTION) {
-                    model.addRow(new ImageryInfo(p.getUrlName(), p.getUrl()));
+                    try {
+                        ImageryInfo info = new ImageryInfo(p.getUrlName(), p.getUrl());
+                        if (ImageryType.TMS.equals(info.getImageryType())) {
+                            TMSLayer.checkUrl(info.getUrl());
+                        }
+                        model.addRow(info);
+                    } catch (IllegalArgumentException ex) {
+                        if (ex.getMessage() == null || ex.getMessage().isEmpty()) {
+                            throw ex;
+                        } else {
+                            JOptionPane.showMessageDialog(Main.parent,
+                                    ex.getMessage(), tr("Error"),
+                                    JOptionPane.ERROR_MESSAGE);
+                        }
+                    }
                 }
             }
