JavaFX默默地吞噬了拖动侦听器中引发的异常 [英] JavaFX silently swallowing exception raised in drag listeners

查看:115
本文介绍了JavaFX默默地吞噬了拖动侦听器中引发的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎在JavaFX中的侦听器上拖拽时会无声地吞下异常。我搜索过,在文档中找不到任何提及。

It appears that exceptions are silently swallowed in drag over listeners in JavaFX. I've searched and can't find any mention of this in the documentation.

我在下面重新创建了这个...

I've recreated this below...

无论如何要防止这种情况并暴露例外情况?

Is there anyway to prevent this and expose the exceptions?

public class App extends Application {

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

    @Override
    public void start(Stage primaryStage) throws Exception {
        Button source = new Button("source");
        Button destination = new Button("destination");
        HBox box = new HBox(source, destination);

        source.setOnDragDetected(event -> {
            Dragboard db = source.startDragAndDrop(TransferMode.ANY);
            ClipboardContent content = new ClipboardContent();
            content.putString("foo");
            db.setContent(content);
            event.consume();
        });
        destination.setOnDragOver(new EventHandler<DragEvent>() {
            public void handle(DragEvent event) {
                event.acceptTransferModes(TransferMode.LINK);
                String nullReference = null; 
                nullReference.toCharArray(); // cause an exception
                event.consume();
            }
        });
        primaryStage.setScene(new Scene(box));
        primaryStage.show();
    }

}

根据James_D的反馈和进一步调查,我们发现这个因平台而异

Following feedback from James_D and further investigation, we have found this varies by platform


  • Ubuntu Linux。 1.8.0_40 =>看到例外情况

  • Mac OS X. 1.8.0_40 =>看到例外情况

  • Windows 7. 1.8.0_40 =>无异常

  • Windows 7. 1.8.0_121 =>无异常(撰写本文时的最新JDK)

  • Ubuntu Linux. 1.8.0_40 => exceptions seen
  • Mac OS X. 1.8.0_40 => exceptions seen
  • Windows 7. 1.8.0_40 => No exceptions
  • Windows 7. 1.8.0_121 => No exceptions (latest JDK at time of writing)

推荐答案

看来本机方法 WinDnDClipboard.push(Object [],int) - 由 GlassClipboard.cpp 默默地吞下异常。可以在调试器中看到对Throwable.getMessage()的回调,但是没有异常打印到控制台。

It appears that native method WinDnDClipboard.push(Object[], int) - backed by GlassClipboard.cpp swallows the exception silently. A call back to Throwable.getMessage() can be seen in the debugger but no exception is printed to the console.

此文件的Java 9版本( http://hg.openjdk.java.net/openjfx/9-dev/rt/file/1a3f128518cd/modules/javafx.graphics/src/main/native-glass/win/GlassClipboard.cpp )对Utils.cpp中定义的 CheckAndClearException(env); 进行额外调用,但这与RT-35400无关。这还没有被移植到Java 8。

The Java 9 version of this file (http://hg.openjdk.java.net/openjfx/9-dev/rt/file/1a3f128518cd/modules/javafx.graphics/src/main/native-glass/win/GlassClipboard.cpp) has an additional call to CheckAndClearException(env); as defined in Utils.cpp, however this is against RT-35400 which appears unrelated. This has not been backported to Java 8.

这篇关于JavaFX默默地吞噬了拖动侦听器中引发的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆