Index: trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java	(revision 783)
+++ trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java	(revision 784)
@@ -10,4 +10,5 @@
 import java.io.InputStreamReader;
 import java.io.OutputStream;
+import java.net.ConnectException;
 import java.net.HttpURLConnection;
 import java.net.URL;
@@ -109,6 +110,12 @@
 			comment = null;
 		}
-		if( useChangesets && !startChangeset(10, comment) )
+		try {
+			if( useChangesets && !startChangeset(10, comment) )
+				return;
+		}
+		catch (OsmTransferException ex) {
+			dealWithTransferException (ex);
 			return;
+		}
 		
 		NameVisitor v = new NameVisitor();
@@ -127,9 +134,24 @@
 				Main.pleaseWaitDlg.progress.setValue(progress+1);
 			}
-			if( useChangesets ) stopChangeset(10);
+				if( useChangesets ) 
+					stopChangeset(10);
 		} catch (RuntimeException e) {
-			if( useChangesets ) stopChangeset(10);
+			try {
+				if( useChangesets ) stopChangeset(10);
+			}
+			catch (OsmTransferException ex) {
+				dealWithTransferException(ex);
+			}
 			e.printStackTrace();
 			throw new SAXException(tr("An error occoured: {0}",e.getMessage()));
+		}
+		catch (OsmTransferException e) {
+			try {
+				if( useChangesets ) stopChangeset(10);
+			}
+			catch (OsmTransferException ex) {
+				dealWithTransferException(ex);	
+			}
+			dealWithTransferException(e);
 		}
 	}
@@ -146,6 +168,8 @@
 	 * can fix the issue where hitting cancel doesn't do anything while
 	 * retrying. - Mv0 Apr 2008
-	 */
-	private boolean startChangeset(int retries, String comment) {
+	 * 
+	 * Cancelling has an effect now, maybe it does not always catch on. Florian Heer, Aug 08
+	 */
+	private boolean startChangeset(int retries, String comment) throws OsmTransferException {
 		Main.pleaseWaitDlg.currentAction.setText(tr("Opening changeset..."));
 		changeset = new Changeset();
@@ -202,9 +226,11 @@
 					OsmWriter.output(o, changeset);
 					System.out.println(new String(o.toByteArray(), "UTF-8").toString());
-					throw new RuntimeException(retCode+" "+retMsg);
+					//throw new RuntimeException(retCode+" "+retMsg);
+					throw new OsmTransferException (retCode + " " + retMsg);
 				}
 			}
 		} catch (UnknownHostException e) {
-			throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e);
+			//throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e);
+			throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e);
 		} catch(SocketTimeoutException e) {
 			System.out.println(" timed out, retries left: " + retries);
@@ -214,8 +240,23 @@
 				startChangeset(retries, comment);
 			else
-				throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
-		} catch (Exception e) {
+				// throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+		}
+		catch (ConnectException e) {
+			System.out.println(" timed out, retries left: " + retries);
 			if (cancel)
 				return false; // assume cancel
+			if (retries-- > 0)
+				startChangeset(retries, comment);
+			else
+				// throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+		}
+		
+		catch (Exception e) {
+			if (cancel)
+				return false; // assume cancel
+			if (e instanceof OsmTransferException)
+				throw (OsmTransferException)e;
 			if (e instanceof RuntimeException)
 				throw (RuntimeException)e;
@@ -225,5 +266,5 @@
 	}
 
-	private void stopChangeset(int retries) {
+	private void stopChangeset(int retries) throws OsmTransferException {
 		Main.pleaseWaitDlg.currentAction.setText(tr("Closing changeset..."));
 		try {
@@ -278,9 +319,11 @@
 					OsmWriter.output(o, changeset);
 					System.out.println(new String(o.toByteArray(), "UTF-8").toString());
-					throw new RuntimeException(retCode+" "+retMsg);
+					//throw new RuntimeException(retCode+" "+retMsg);
+					throw new OsmTransferException(retCode+" "+retMsg);
 				}
 			}
 		} catch (UnknownHostException e) {
-			throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e);
+			//throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e);
+			throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e);
 		} catch(SocketTimeoutException e) {
 			System.out.println(" timed out, retries left: " + retries);
@@ -290,8 +333,20 @@
 				stopChangeset(retries);
 			else
-				throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				//throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				throw new OsmTransferException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+		} catch(ConnectException e) {
+			System.out.println(" timed out, retries left: " + retries);
+			if (cancel)
+				return; // assume cancel
+			if (retries-- > 0)
+				stopChangeset(retries);
+			else
+				//throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				throw new OsmTransferException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
 		} catch (Exception e) {
 			if (cancel)
 				return; // assume cancel
+			if (e instanceof OsmTransferException)
+				throw (OsmTransferException)e;
 			if (e instanceof RuntimeException)
 				throw (RuntimeException)e;
@@ -361,5 +416,5 @@
 	 */
 	private void sendRequestRetry(String requestMethod, String urlSuffix,
-			OsmPrimitive osm, OsmWriterInterface body, int retries) {
+			OsmPrimitive osm, OsmWriterInterface body, int retries) throws OsmTransferException {
 		try {
 			if (cancel)
@@ -371,5 +426,5 @@
 					urlSuffix + 
 					"/" + (osm.id==0 ? "create" : osm.id),
-					(java.net.URLStreamHandler)new MyHttpHandler());
+					new MyHttpHandler());
 			System.out.print("upload to: "+url+ "..." );
 			activeConnection = (HttpURLConnection)url.openConnection();
@@ -421,9 +476,11 @@
 					OsmWriter.output(o, body);
 					System.out.println(new String(o.toByteArray(), "UTF-8").toString());
-					throw new RuntimeException(retCode+" "+retMsg);
+					//throw new RuntimeException(retCode+" "+retMsg);
+					throw new OsmTransferException(retCode+" "+retMsg);
 				}
 			}
 		} catch (UnknownHostException e) {
-			throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e);
+			//throw new RuntimeException(tr("Unknown host")+": "+e.getMessage(), e);
+			throw new OsmTransferException(tr("Unknown host")+": "+e.getMessage(), e);
 		} catch(SocketTimeoutException e) {
 			System.out.println(" timed out, retries left: " + retries);
@@ -433,8 +490,20 @@
 				sendRequestRetry(requestMethod, urlSuffix, osm, body, retries);
 			else
-				throw new RuntimeException(e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				//throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+		} catch(ConnectException e) {
+			System.out.println(" timed out, retries left: " + retries);
+			if (cancel)
+				return; // assume cancel
+			if (retries-- > 0)
+				sendRequestRetry(requestMethod, urlSuffix, osm, body, retries);
+			else
+				//throw new RuntimeException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
+				throw new OsmTransferException (e.getMessage()+ " " + e.getClass().getCanonicalName(), e);
 		} catch (Exception e) {
 			if (cancel)
 				return; // assume cancel
+			if (e instanceof OsmTransferException)
+				throw (OsmTransferException)e;
 			if (e instanceof RuntimeException)
 				throw (RuntimeException)e;
@@ -442,11 +511,26 @@
 		}
 	}
+	
 	private void sendRequest(String requestMethod, String urlSuffix,
-			OsmPrimitive osm, boolean addBody) {
+			OsmPrimitive osm, boolean addBody)  {
 		XmlWriter.OsmWriterInterface body = null;
 		if (addBody) {
 				body = new OsmWriter.Single(osm, true, changeset);
 		}
-		sendRequestRetry(requestMethod, urlSuffix, osm, body, 10);
+		try {
+			sendRequestRetry(requestMethod, urlSuffix, osm, body, 10);
+		}
+		catch (OsmTransferException e) {
+			dealWithTransferException (e);
+		}
+	}
+	
+	private void dealWithTransferException (OsmTransferException e) {
+		Main.pleaseWaitDlg.currentAction.setText(tr("Transfer aborted due to error (will wait now 5 seconds):") + e.getMessage());
+		cancel = true;
+		try {
+			Thread.sleep(5000);
+		}
+		catch (InterruptedException ex) {}
 	}
 }
Index: trunk/src/org/openstreetmap/josm/io/OsmTransferException.java
===================================================================
--- trunk/src/org/openstreetmap/josm/io/OsmTransferException.java	(revision 784)
+++ trunk/src/org/openstreetmap/josm/io/OsmTransferException.java	(revision 784)
@@ -0,0 +1,21 @@
+// License: GPL. For details, see LICENSE file.
+package org.openstreetmap.josm.io;
+
+public class OsmTransferException extends Exception {
+
+	public OsmTransferException() {
+	}
+
+	public OsmTransferException(String message) {
+		super(message);
+	}
+
+	public OsmTransferException(Throwable cause) {
+		super(cause);
+	}
+
+	public OsmTransferException(String message, Throwable cause) {
+		super(message, cause);
+	}
+
+}
