Skip to content

Commit db2a1c8

Browse files
Pack original exception into runtime exception
1 parent e4f1478 commit db2a1c8

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

pacman-ui/src/main/java/de/amr/pacmanfx/ui/GameUI_Builder.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ private StartPage createStartPage(GameUI ui, String gameVariant, Class<?> startP
156156
var constructor = startPageClass.getDeclaredConstructor(GameUI.class);
157157
return (StartPage) constructor.newInstance(ui);
158158
} catch (Exception xx) {
159-
error("Could not create start page from class '%s'".formatted(startPageClass.getSimpleName()));
159+
error("Could not create start page from class '%s'".formatted(startPageClass.getSimpleName()), xx);
160160
throw new IllegalStateException(xx);
161161
}
162162
} catch (Exception x) {
163-
error("Could not create start page from class '%s'".formatted(startPageClass.getSimpleName()));
163+
error("Could not create start page from class '%s'".formatted(startPageClass.getSimpleName()), x);
164164
throw new IllegalStateException(x);
165165
}
166166
}
@@ -175,7 +175,7 @@ private Game createGameModel(Class<?> modelClass, MapSelector mapSelector, GameC
175175
? modelClass.getDeclaredConstructor(GameContext.class, MapSelector.class, File.class).newInstance(gameContext, mapSelector, highScoreFile)
176176
: modelClass.getDeclaredConstructor(GameContext.class, File.class).newInstance(gameContext, highScoreFile));
177177
} catch (Exception x) {
178-
error("Could not create game model from class %s".formatted(modelClass.getSimpleName()));
178+
error("Could not create game model from class %s".formatted(modelClass.getSimpleName()), x);
179179
throw new RuntimeException(x);
180180
}
181181
}
@@ -204,6 +204,10 @@ private void validateGameVariantKey(String key) {
204204
}
205205
}
206206

207+
private void error(String message, Throwable x) {
208+
throw new RuntimeException("UI building failed: %s".formatted(message), x);
209+
}
210+
207211
private void error(String message) {
208212
throw new RuntimeException("UI building failed: %s".formatted(message));
209213
}

0 commit comments

Comments
 (0)