Skip to content

Commit

Permalink
Log all JavaFX runtime errors
Browse files Browse the repository at this point in the history
Previously they would end up in stdout, which is invisible when the app is installed and running from a launcher.

A requester is also shown since most JavaFX crashes have serious consequences (dead UI, etc...)
  • Loading branch information
zapek committed Dec 26, 2024
1 parent 5443ae6 commit 79478db
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
9 changes: 9 additions & 0 deletions ui/src/main/java/io/xeres/ui/JavaFxApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import io.xeres.common.mui.MinimalUserInterface;
import io.xeres.ui.support.uri.UriService;
import io.xeres.ui.support.util.UiUtils;
import javafx.application.Application;
import javafx.stage.Stage;
import org.springframework.boot.builder.SpringApplicationBuilder;
Expand Down Expand Up @@ -65,6 +66,9 @@ public void start(Stage primaryStage)
{
Objects.requireNonNull(springContext);

// This allows all JavaFX crashes to show up in the logger instead of stdout
Thread.setDefaultUncaughtExceptionHandler(JavaFxApplication::handleException);

var openUrlService = springContext.getBean(UriService.class);
openUrlService.setHostServices(getHostServices());

Expand All @@ -76,4 +80,9 @@ public void stop()
{
springContext.close();
}

private static void handleException(Thread thread, Throwable throwable)
{
UiUtils.showAlertError(throwable);
}
}
4 changes: 2 additions & 2 deletions ui/src/main/java/io/xeres/ui/support/util/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,14 @@ public static void showAlertError(Throwable t, Runnable action)
}
else
{
alert(ERROR, "Error", t.getMessage(), ExceptionUtils.getStackTrace(t));
alert(ERROR, "Error", t.getClass().getSimpleName() + ": " + t.getMessage(), ExceptionUtils.getStackTrace(t));
}
if (action != null)
{
action.run();
}
log.error("Error: {}", t.getMessage(), t);
});
log.error("Error: {}", t.getMessage(), t);
}

public static void showError(Node... nodes)
Expand Down

0 comments on commit 79478db

Please sign in to comment.