Debug exceptions in AWT queue thread

后端 未结 3 460
执念已碎
执念已碎 2020-12-21 10:47

I am developing a Swing application with a component performing custom painting. When I make some mistake in the painting code and an exception is thrown, the situation is h

3条回答
  •  被撕碎了的回忆
    2020-12-21 11:14

    Looks like your only solution might be switching to Eclipse. :-) The other solutions require coding effort and stopping in the exception handler is not the same as stopping in the exact place where the exception is thrown.

    With the following program I have no problems listening to caught/uncaught instances of RuntimeException in Eclipse.

    package lambda;
    
    import java.awt.Dimension;
    
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.SwingUtilities;
    
    public class AWTExceptionTest {
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            JButton button = new JButton("Test");
            button.addActionListener(e -> { throw new RuntimeException(); });
            frame.add(button);
            frame.setSize(new Dimension(50, 50));
            SwingUtilities.invokeLater(() -> frame.setVisible(true));
        }
    }
    

    Here is how it looks in debug mode in Eclipse.

    Eclipse in Debug mode

提交回复
热议问题