代码之家  ›  专栏  ›  技术社区  ›  Thirler

对于swingutilities.invokeAndWait引发的异常,我应该怎么做?

  •  4
  • Thirler  · 技术社区  · 16 年前

    SwingUtilities.invokeAndWait() 抛出一个 InterruptedException 和一个 InvocationTargetException 我该怎么处理这些?

     public static void invokeAndWait(Runnable doRun) throws InterruptedException,
                                     InvocationTargetException
    

    我想用这个方法显示一个对话框,并等待用户说是或否。 调用目标异常 意味着有一个 RuntimeException 我可以这样对待它。但是我真正想要的是 中断例外 就是忽略它,让线程继续运行,直到用户给出答案。

    2 回复  |  直到 16 年前
        1
  •  2
  •   fulkod    16 年前

    article

            try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    System.out.println("1");
                    if (true) {
                        throw new RuntimeException("runtime exception");
                    }
                    System.out.println("2");
                }
            });
        } catch (InterruptedException e) {
            e.printStackTrace(System.out);
        } catch (InvocationTargetException e) {
            e.printStackTrace(System.out);
        }
    
        2
  •  1
  •   Luhar    16 年前