gpt4 book ai didi

java - Throwable 参数 'ex' 到 'System.out.println()' 调用

转载 作者:行者123 更新时间:2023-12-01 14:10:21 27 4
gpt4 key购买 nike

我目前正在研究一个库存管理系统。在系统中有注册选项,如下所示:

Registration page

以下代码显示了注册按钮方法:

        btnRegister.setOnAction(e ->{// register button method
try {
Stage stage = new Stage();
FXMLLoader loader = new FXMLLoader();
Pane root = loader.load(getClass().getResource("Register.fxml").openStream());
RegisterController Msg = loader.getController();
Scene scene = new Scene(root);
scene.getStylesheets().setAll(
getClass().getResource("style.css").toExternalForm()
);
stage.setScene(scene);
stage.show();
((Node) e.getSource()).getScene().getWindow().hide();

} catch (Exception ex) {
System.out.println(ex);
}
});


我收到以下警告:
Warning:(64, 36) Throwable argument 'ex' to 'System.out.println()' call

有人可以解释这个警告以及解决这个问题的可能方法吗?

如果被忽略,这会对以后的新更改产生任何影响吗?

它专门提示 register 方法中的以下代码行,其中异常是:
} catch (Exception ex) {
System.out.println(ex);
}

最佳答案

为了打印异常详细信息,异常类已经有一个方法名称“printStackTrace()”,

 System.out.println(ex); //not recommended 

用这个
ex.printStackTrace();

关于java - Throwable 参数 'ex' 到 'System.out.println()' 调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61927493/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com