Although RT-15332 has been closed, I believe I have proof that the issue is not yet solved. JavaFX still catches all exceptions at least in 1 situation (there may be more, and I suggest you look for them). Here is the problematic code, I have found in file LauncherImpl:
PlatformImpl.runAndWait(() -> {
try {
startCalled.set(true);
// Create primary stage and call application start method
final Stage primaryStage = new Stage();
primaryStage.impl_setPrimary(true);
theApp.start(primaryStage);
} catch (Throwable t) {
System.err.println("Exception in Application start method");
startError = t;
error = true;
}
});
As you can see, when theApp.start() is invoked, the code above catches all exceptions, thereby preventing our application code from carrying out its traditional Java default exception handling. You can verify the bug by running the test sample below.
I think this bug is not to be taken lightly. Many professional applications implement default handling of uncaught exceptions that carry out tasks which are important. In our app for instance, if an uncaught exception occurs, our app will log the exception in a database and have our server send an e-mail to the quality assurance team. However, when JavaFX steps in, and grabs all the exceptions, this does not happen.
If you want JavaFX to catch uncaught exceptions, please follow the traditional Java pattern for doing so, thereby allowing us to replace your default handling with ours.
public class ExceptionTest extends Application {
private Thread.UncaughtExceptionHandler uncaughtHandler =
new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, final Throwable exception) {
System.out.println("Caught uncaught exception.");
}
};
@Override
public void start(Stage primaryStage) throws Exception {
Thread.setDefaultUncaughtExceptionHandler(uncaughtHandler);
Thread.currentThread().setUncaughtExceptionHandler(uncaughtHandler);
Platform.runLater(() -> {
Thread.currentThread().setUncaughtExceptionHandler(uncaughtHandler);
});
throw new RuntimeException("This is never caught by the handler as it should.");
}
public static void main(String... arguments) {
launch(ExceptionTest.class, arguments);
}
}