1

I'm writing a JavaFX app exclusively for Windows, where the app is required to crash and produce a generic "Application has Stopped Working" Error Dialogue as seen here when the client uses a pirated serial key for the app's activation.

Is this possible to do?

DarkMental
  • 482
  • 7
  • 26
  • `System.err.println("Application has stopped working"); System.exit(1);`? – fabian Feb 07 '18 at 10:30
  • @fabian Oh sorry i wasn't clear, the client should be introduced with the "Application has stopped working" dialogue, you see [here](https://img.raymond.cc/blog/wp-content/uploads/2009/08/program_has_stopped_working_error.png). I'll edit my question – DarkMental Feb 07 '18 at 10:32
  • 2
    Not really sure exactly what you're looking for. You could just hang it intentionally: `Platform.runLater(() -> { while (true) ; });`. That would make it non-responsive, not sure if it is enough for Windows to detect it has "stopped working". But why not just show your own modal dialog and exit when it closes? – James_D Feb 07 '18 at 12:44
  • I would assume you can not "reproduce" this without having the knowledge if this is reproducable on your clients system. It might be a different JDK or other systems (like AV or malware) could interfere the normal work. This is normal "debugging hell". – FibreFoX Feb 08 '18 at 09:50

1 Answers1

1

You can use the Alert class with the ERROR alert type.
Below is a working example:

MyApplication.java

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage primaryStage) {
    try {
        // do something
        throw new RuntimeException();
    } catch (Exception ex) {
        displayApplicationError();
    }

}

private void displayApplicationError() {
    Platform.runLater(() -> {
        new ApplicationError().start(new Stage());
        Platform.exit();
    });
}

ApplicationError.java

public static void main(String[] args) {
    launch(args);
}

@Override
public void start(Stage stage) {
    Alert alert = new Alert(AlertType.ERROR);
    alert.setTitle("ERROR");
    alert.setHeaderText(null);
    alert.setContentText("Application has Stopped Working");
    alert.showAndWait();
}

enter image description here

The alert will have a native look and feel on Windows, you can find more examples here.

Boris
  • 22,667
  • 16
  • 50
  • 71