Way can´t I handle exception in javaFx like this

Viewed 24

*Way don´t I get the code below to work, for example if I put it in a context of opening a file that doesn't exist? ... @FXML private void openLink(ActionEvent event) {

        Dialog<ButtonType> dialog = new Dialog<ButtonType>();
        dialog.setTitle("Program exception");
        final DialogPane dialogPane = dialog.getDialogPane();
        dialogPane.getButtonTypes().addAll(ButtonType.OK);
        dialogPane.getButtonTypes().addAll(ButtonType.CLOSE);
        
        dialogPane.setContentText("This is an exception message");
        dialog.initModality(Modality.APPLICATION_MODAL);
        
        StringWriter sw = new StringWriter(); // to display in text area
        PrintWriter pw = new PrintWriter(sw);
        
         try {
            String url = null; // <- creating a custom exception
            Desktop.getDesktop().browse(new URI(url));
         } catch (IOException | URISyntaxException e) {
             
            e.printStackTrace(pw); // Handle e
            pw.close(); // Handle e
             
         }
            Label label = new Label("Exception StackTraceS");
            TextArea textArea = new TextArea(sw.toString());
            textArea.setEditable(false);
            textArea.setWrapText(true);
            
            textArea.setMaxWidth(Double_VALUE);
            textArea.setMaxHeight(Double_VALUE);
            
            GridPane root = new GridPane();
            root.setVisible(false);
            root.add(label, 0, 0);
            root.add(textArea, 0, 1);
            dialogPane.setExpandableContent(root);
            dialog.showAndWait();
    }

...

0 Answers
Related