From 45ea7b26995967c8c49825a6636f22bcaef03c48 Mon Sep 17 00:00:00 2001 From: FlorianMichael <60033407+FlorianMichael@users.noreply.github.com> Date: Tue, 21 Mar 2023 22:41:28 +0100 Subject: [PATCH] added more Error handling to File saving --- .../viafabricplus/util/FileSaver.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/florianmichael/viafabricplus/util/FileSaver.java b/src/main/java/de/florianmichael/viafabricplus/util/FileSaver.java index c8f658ae..3468f936 100644 --- a/src/main/java/de/florianmichael/viafabricplus/util/FileSaver.java +++ b/src/main/java/de/florianmichael/viafabricplus/util/FileSaver.java @@ -31,13 +31,15 @@ public abstract class FileSaver { public void init() { if (file.exists()) { - final JsonObject parentNode; + JsonObject parentNode = null; try { parentNode = ViaFabricPlus.GSON.fromJson(new FileReader(file), JsonObject.class).getAsJsonObject(); - } catch (FileNotFoundException e) { - throw new RuntimeException(e); + } catch (Exception e) { + e.printStackTrace(); + } + if (parentNode != null) { + read(parentNode); } - read(parentNode); } Runtime.getRuntime().addShutdownHook(new Thread(() -> { @@ -45,7 +47,7 @@ public abstract class FileSaver { try { file.createNewFile(); } catch (IOException e) { - throw new RuntimeException(e); + e.printStackTrace(); } try (final FileWriter fw = new FileWriter(file)) { @@ -54,7 +56,7 @@ public abstract class FileSaver { fw.write(ViaFabricPlus.GSON.toJson(parentNode)); fw.flush(); } catch (IOException e) { - throw new RuntimeException(e); + e.printStackTrace(); } })); }