public void testTriggerExceptionsAreStoredAndRethrownWhenNotCaughtImmediately() throws Exception {
    final Exception exception = new RuntimeException("unexpected production code exception");
    Window window1 =
        WindowInterceptor.getModalDialog(
            new Trigger() {
              public void run() throws Exception {
                JDialog dialog = createModalDialog("dialog");
                addHideButton(dialog, "OK");
                dialog.setVisible(true);
                JDialog dialog2 = createModalDialog("dialog2");
                addHideButton(dialog2, "OK");
                dialog2.setVisible(true);
                throw exception;
              }
            });

    Window window2 = WindowInterceptor.getModalDialog(window1.getButton("OK").triggerClick());
    window2.titleEquals("dialog2");
    window2.getButton("OK").click();
    Utils.sleep(1);

    try {
      WindowInterceptor.run(
          new Trigger() {
            public void run() throws Exception {
              JDialog dialog3 = new JDialog();
              addHideButton(dialog3, "OK");
              dialog3.setVisible(true);
            }
          });
      fail();
    } catch (Exception e) {
      assertSame(exception, e.getCause());
    }
  }