code: public void invokeTask (Component parent, String retryMessage)
          throws Exception
      {
          while (true) {
              try {
                  invoke();
                  return;
  
              } catch (Exception e) {
                  Object[] options = new Object[] {
                      "Retry operation", "Abort operation" };
                  int rv = JOptionPane.showOptionDialog(
                      parent, retryMessage + "\n\n" + e.getMessage(),
                      "Operation failure", JOptionPane.YES_NO_OPTION,
                      JOptionPane.WARNING_MESSAGE, null, options, options[1]);
                  if (rv == 1) {
                      throw e;
                  }
              }
          }
      }
docs: Invokes the supplied task and catches any thrown exceptions. In the
  event of an exception, the provided message is displayed to the
  user and the are allowed to retry the task or allow it to fail.