Changeset 14950 in josm


Ignore:
Timestamp:
2019-04-01T22:01:06+02:00 (5 years ago)
Author:
GerdP
Message:

fix #17238 Don't know why I forgot to commit this patch.

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/GpxExportAction.java

    r14397 r14950  
    1010import java.io.File;
    1111import java.io.IOException;
     12import java.nio.file.InvalidPathException;
    1213import java.text.MessageFormat;
    1314
     
    2122import org.openstreetmap.josm.gui.layer.OsmDataLayer;
    2223import org.openstreetmap.josm.tools.CheckParameterUtil;
    23 import org.openstreetmap.josm.tools.Logging;
    2424import org.openstreetmap.josm.tools.Shortcut;
    2525
     
    108108                try {
    109109                    exporter.exportData(file, layer);
    110                 } catch (IOException e) {
    111                     Logging.error(e);
     110                } catch (IOException | InvalidPathException e) {
     111                    SaveActionBase.showAndLogException(e);
    112112                }
    113113            }
  • trunk/src/org/openstreetmap/josm/actions/SaveActionBase.java

    r14153 r14950  
    77import java.io.File;
    88import java.io.IOException;
     9import java.nio.file.InvalidPathException;
    910import java.util.Collection;
    1011import java.util.LinkedList;
     
    2627import org.openstreetmap.josm.tools.Logging;
    2728import org.openstreetmap.josm.tools.Shortcut;
     29import org.openstreetmap.josm.tools.Utils;
    2830
    2931/**
     
    121123            }
    122124            MainApplication.getMainFrame().repaint();
    123         } catch (IOException e) {
    124             Logging.error(e);
     125        } catch (IOException | InvalidPathException e) {
     126            showAndLogException(e);
    125127            return false;
    126128        }
     
    240242        PreferencesUtils.putListBounded(Config.getPref(), "file-open.history", maxsize, history);
    241243    }
     244
     245    static void showAndLogException(Exception e) {
     246        GuiHelper.runInEDT(() ->
     247        JOptionPane.showMessageDialog(
     248                MainApplication.getMainFrame(),
     249                tr("<html>An error occurred while saving.<br>Error is:<br>{0}</html>",
     250                        Utils.escapeReservedCharactersHTML(e.getClass().getSimpleName() + " - " + e.getMessage())),
     251                tr("Error"),
     252                JOptionPane.ERROR_MESSAGE
     253                ));
     254
     255        Logging.error(e);
     256    }
    242257}
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/FileExporter.java

    r12671 r14950  
    1717public abstract class FileExporter implements ActiveLayerChangeListener {
    1818
     19    /** the  ExtensionFileFilter filter used by this exporter */
    1920    public final ExtensionFileFilter filter;
    2021
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/GpxExporter.java

    r14153 r14950  
    1111import java.io.IOException;
    1212import java.io.OutputStream;
    13 import java.nio.file.InvalidPathException;
    1413import java.text.MessageFormat;
    1514import java.time.Year;
     
    3938import org.openstreetmap.josm.tools.CheckParameterUtil;
    4039import org.openstreetmap.josm.tools.GBC;
    41 import org.openstreetmap.josm.tools.Logging;
    4240
    4341/**
     
    206204        }
    207205
    208         try (OutputStream fo = Compression.getCompressedFileOutputStream(file)) {
    209             new GpxWriter(fo).write(gpxData);
    210             fo.flush();
    211         } catch (IOException | InvalidPathException ex) {
    212             Logging.error(ex);
    213             JOptionPane.showMessageDialog(MainApplication.getMainFrame(), tr("Error while exporting {0}:\n{1}", fn, ex.getMessage()),
    214                     tr("Error"), JOptionPane.ERROR_MESSAGE);
     206        try (OutputStream fo = Compression.getCompressedFileOutputStream(file); GpxWriter writer = new GpxWriter(fo)) {
     207            writer.write(gpxData);
    215208        }
    216209    }
  • trunk/src/org/openstreetmap/josm/gui/io/importexport/OsmExporter.java

    r14296 r14950  
    6767     * @param noBackup if {@code true}, the potential backup file created if the output file already exists will be deleted
    6868     *                 after a successful export
     69     * @throws IOException in case of IO errors
     70     * @throws InvalidPathException when file name cannot be converted into a Path
    6971     * @throws IllegalArgumentException if {@code layer} is not an instance of {@code OsmDataLayer}
    7072     */
    71     public void exportData(File file, Layer layer, boolean noBackup) {
     73    public void exportData(File file, Layer layer, boolean noBackup) throws IOException {
    7274        if (!(layer instanceof OsmDataLayer)) {
    7375            throw new IllegalArgumentException(
     
    8183    }
    8284
    83     private void save(File file, OsmDataLayer layer, boolean noBackup) {
     85    private void save(File file, OsmDataLayer layer, boolean noBackup) throws IOException {
    8486        File tmpFile = null;
    8587        try {
     88
    8689            // use a tmp file because if something errors out in the process of writing the file,
    8790            // we might just end up with a truncated file.  That can destroy lots of work.
     
    98101        } catch (IOException | InvalidPathException e) {
    99102            Logging.error(e);
    100             JOptionPane.showMessageDialog(
    101                     MainApplication.getMainFrame(),
    102                     tr("<html>An error occurred while saving.<br>Error is:<br>{0}</html>",
    103                             Utils.escapeReservedCharactersHTML(e.getClass().getSimpleName() + " - " + e.getMessage())),
    104                     tr("Error"),
    105                     JOptionPane.ERROR_MESSAGE
    106             );
    107103
    108104            try {
     
    121117                );
    122118            }
     119            // re-throw original error
     120            throw e;
    123121        }
    124122    }
Note: See TracChangeset for help on using the changeset viewer.