我正在设计一个由于许多原因而显示未处理异常的应用程序。所以我想让我的应用程序在catch块中显示警报。
最佳答案
您可以执行以下操作:
private Alert alert;
private Display display;
// Obtain display with display = Display.getDisplay(this); in consturctor
catch(Exception e) {
alert = new Alert("Error occurred", "Message: " + e.getMessage(), null, AlertType.ERROR);
alert.setTimeout(Alert.FOREVER);
display.setCurrent(alert, form);
}
希望这可以帮助。