Skip to content

Commit 2f6d211

Browse files
committed
Simplified overly complicated error handling in PApplet.createWriter
1 parent 9eeb79f commit 2f6d211

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

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

+8-11
Original file line numberDiff line numberDiff line change
@@ -552,23 +552,20 @@ static final public String[] str(int x[]) {
552552
/**
553553
* I want to print lines to a file. I have RSI from typing these
554554
* eight lines of code so many times.
555+
* @throws IOException
555556
*/
556-
static public PrintWriter createWriter(File file) {
557+
static public PrintWriter createWriter(File file) throws IOException {
558+
createPath(file); // make sure in-between folders exist
559+
OutputStream output = new FileOutputStream(file);
557560
try {
558-
createPath(file); // make sure in-between folders exist
559-
OutputStream output = new FileOutputStream(file);
560561
if (file.getName().toLowerCase().endsWith(".gz")) {
561562
output = new GZIPOutputStream(output);
562563
}
563-
return createWriter(output);
564-
565-
} catch (Exception e) {
566-
if (file == null) {
567-
throw new RuntimeException("File passed to createWriter() was null");
568-
} else {
569-
throw new RuntimeException("Couldn't create a writer for " + file.getAbsolutePath(), e);
570-
}
564+
} catch (IOException e) {
565+
output.close();
566+
throw e;
571567
}
568+
return createWriter(output);
572569
}
573570

574571

0 commit comments

Comments
 (0)