- Timestamp:
- 2009-08-12T09:27:57+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java
r1885 r1957 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException; 6 7 import java.net.HttpURLConnection; 7 8 import java.net.MalformedURLException; … … 152 153 */ 153 154 155 public static void explainNestedIOException(OsmTransferException e) { 156 IOException ioe = getNestedException(e, IOException.class); 157 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 158 String message = tr("<html>Failed to upload data to or download data from<br>" 159 + "''{0}''<br>" 160 + "due to a problem with transferring data.<br>" 161 + "Details(untranslated): {1}</html>", 162 apiUrl, ioe.getMessage() 163 ); 164 e.printStackTrace(); 165 OptionPaneUtil.showMessageDialog( 166 Main.parent, 167 message, 168 tr("IO Exception"), 169 JOptionPane.ERROR_MESSAGE 170 ); 171 } 172 173 /** 174 * Explains a {@see SecurityException} which has caused an {@see OsmTransferException}. 175 * This is most likely happening when user tries to access the OSM API from whitin an 176 * applet which wasn't loaded from the API server. 177 * 178 * @param e the exception 179 */ 180 154 181 public static void explainNestedUnkonwnHostException(OsmTransferException e) { 155 182 String apiUrl = OsmApi.getOsmApi().getBaseUrl(); … … 176 203 } 177 204 178 protected static <T> T getNestedException(Exception e, Class<T> nested) { 205 /** 206 * Replies the first nested exception of type <code>nestedClass</code> (including 207 * the root exception <code>e</code>) or null, if no such exception is found. 208 * 209 * @param <T> 210 * @param e the root exception 211 * @param nestedClass the type of the nested exception 212 * @return the first nested exception of type <code>nestedClass</code> (including 213 * the root exception <code>e</code>) or null, if no such exception is found. 214 */ 215 protected static <T> T getNestedException(Exception e, Class<T> nestedClass) { 179 216 Throwable t = e; 180 while (t != null && !( t.getClass().isAssignableFrom(nested))) {217 while (t != null && !(nestedClass.isInstance(t))) { 181 218 t = t.getCause(); 182 219 } 183 return nested.cast(t); 184 } 185 186 /** 187 * Replies the first {@see SecurityException} in a chain of nested exceptions. 188 * null, if no {@see SecurityException} is in this chain. 189 * 190 * @param e the root exception 191 * @return the first {@see SecurityException} in a chain of nested exceptions 192 */ 193 protected static SecurityException getNestedSecurityException(Exception e) { 194 return getNestedException(e, SecurityException.class); 195 } 196 197 198 /** 199 * Replies the first {@see SocketException} in a chain of nested exceptions. 200 * null, if no {@see SocketException} is in this chain. 201 * 202 * @param e the root exception 203 * @return the first {@see SocketException} in a chain of nested exceptions 204 */ 205 protected static SocketException getNestedSocketException(Exception e) { 206 return getNestedException(e, SocketException.class); 207 } 208 209 /** 210 * Replies the first {@see UnknownHostException} in a chain of nested exceptions. 211 * null, if no {@see UnknownHostException} is in this chain. 212 * 213 * @param e the root exception 214 * @return the first {@see UnknownHostException} in a chain of nested exceptions 215 */ 216 protected static UnknownHostException getNestedUnknownHostException(Exception e) { 217 return getNestedException(e, UnknownHostException.class); 218 } 219 220 if (t== null) 221 return null; 222 else if (nestedClass.isInstance(t)) 223 return nestedClass.cast(t); 224 return null; 225 } 220 226 221 227 /** … … 225 231 */ 226 232 public static void explainOsmTransferException(OsmTransferException e) { 227 if (getNested SecurityException(e) != null) {233 if (getNestedException(e, SecurityException.class) != null) { 228 234 explainSecurityException(e); 229 235 return; 230 236 } 231 if (getNested SocketException(e) != null) {237 if (getNestedException(e, SocketException.class) != null) { 232 238 explainNestedSocketException(e); 233 239 return; 234 240 } 235 if (getNested UnknownHostException(e) != null) {241 if (getNestedException(e, UnknownHostException.class) != null) { 236 242 explainNestedUnkonwnHostException(e); 243 return; 244 } 245 if (getNestedException(e, IOException.class) != null) { 246 explainNestedIOException(e); 237 247 return; 238 248 } … … 252 262 } 253 263 } 254 255 264 explainGeneric(e); 256 265 }
Note:
See TracChangeset
for help on using the changeset viewer.