Changeset 1957 in josm


Ignore:
Timestamp:
Aug 12, 2009 9:27:57 AM (4 years ago)
Author:
Gubaer
Message:

fixed #3248: Exception occured

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/ExceptionDialogUtil.java

    r1885 r1957  
    44import static org.openstreetmap.josm.tools.I18n.tr; 
    55 
     6import java.io.IOException; 
    67import java.net.HttpURLConnection; 
    78import java.net.MalformedURLException; 
     
    152153     */ 
    153154 
     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 
    154181    public static void explainNestedUnkonwnHostException(OsmTransferException e) { 
    155182        String apiUrl = OsmApi.getOsmApi().getBaseUrl(); 
     
    176203    } 
    177204 
    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) { 
    179216        Throwable t = e; 
    180         while (t != null && !(t.getClass().isAssignableFrom(nested))) { 
     217        while (t != null && !(nestedClass.isInstance(t))) { 
    181218            t = t.getCause(); 
    182219        } 
    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    } 
    220226 
    221227    /** 
     
    225231     */ 
    226232    public static void explainOsmTransferException(OsmTransferException e) { 
    227         if (getNestedSecurityException(e) != null) { 
     233        if (getNestedException(e, SecurityException.class) != null) { 
    228234            explainSecurityException(e); 
    229235            return; 
    230236        } 
    231         if (getNestedSocketException(e) != null) { 
     237        if (getNestedException(e, SocketException.class) != null) { 
    232238            explainNestedSocketException(e); 
    233239            return; 
    234240        } 
    235         if (getNestedUnknownHostException(e) != null) { 
     241        if (getNestedException(e, UnknownHostException.class) != null) { 
    236242            explainNestedUnkonwnHostException(e); 
     243            return; 
     244        } 
     245        if (getNestedException(e, IOException.class) != null) { 
     246            explainNestedIOException(e); 
    237247            return; 
    238248        } 
     
    252262            } 
    253263        } 
    254  
    255264        explainGeneric(e); 
    256265    } 
Note: See TracChangeset for help on using the changeset viewer.