Skip to content

Commit 9eeb79f

Browse files
committed
Do not crash if preferences.txt can't be written
1 parent 99fe051 commit 9eeb79f

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

arduino-core/src/processing/app/PreferencesData.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
package processing.app;
22

3-
import org.apache.commons.compress.utils.IOUtils;
4-
5-
import cc.arduino.i18n.Languages;
6-
import processing.app.helpers.PreferencesHelper;
7-
import processing.app.helpers.PreferencesMap;
8-
import processing.app.legacy.PApplet;
9-
import processing.app.legacy.PConstants;
3+
import static processing.app.I18n.format;
4+
import static processing.app.I18n.tr;
105

11-
import java.awt.*;
6+
import java.awt.Font;
127
import java.io.File;
138
import java.io.IOException;
149
import java.io.PrintWriter;
@@ -18,7 +13,13 @@
1813
import java.util.MissingResourceException;
1914
import java.util.stream.Collectors;
2015

21-
import static processing.app.I18n.tr;
16+
import org.apache.commons.compress.utils.IOUtils;
17+
18+
import cc.arduino.i18n.Languages;
19+
import processing.app.helpers.PreferencesHelper;
20+
import processing.app.helpers.PreferencesMap;
21+
import processing.app.legacy.PApplet;
22+
import processing.app.legacy.PConstants;
2223

2324

2425
public class PreferencesData {
@@ -136,6 +137,9 @@ static protected void save() {
136137
}
137138

138139
writer.flush();
140+
} catch (Throwable e) {
141+
System.err.println(format(tr("Could not write preferences file: {0}"), e.getMessage()));
142+
return;
139143
} finally {
140144
IOUtils.closeQuietly(writer);
141145
}

arduino-core/src/processing/app/legacy/PApplet.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -566,12 +566,9 @@ static public PrintWriter createWriter(File file) {
566566
if (file == null) {
567567
throw new RuntimeException("File passed to createWriter() was null");
568568
} else {
569-
e.printStackTrace();
570-
throw new RuntimeException("Couldn't create a writer for " +
571-
file.getAbsolutePath());
569+
throw new RuntimeException("Couldn't create a writer for " + file.getAbsolutePath(), e);
572570
}
573571
}
574-
//return null;
575572
}
576573

577574

0 commit comments

Comments
 (0)