Beispiel #1
0
 /**
  * Returns a nice localized message for the passed exception in case it is possible, or toString()
  * otherwise.
  */
 static String getLocalizedMessage(Throwable e) {
   String localizedMessage;
   try {
     // try to load localized message
     if (e instanceof UserErrorException) {
       localizedMessage = e.getMessage();
     } else {
       String exceptionClassName = e.getClass().getSimpleName();
       String originalMessage = e.getMessage();
       localizedMessage =
           Labels.getLabel(
               "exception."
                   + exceptionClassName
                   + (originalMessage != null ? "." + originalMessage : ""));
     }
     // add cause summary, if it exists
     if (e.getCause() != null) {
       localizedMessage += "\n\n" + e.getCause().toString();
     }
     LOG.log(Level.FINE, "error", e);
   } catch (Exception e2) {
     // fallback to default text
     localizedMessage = e.toString();
     // output stack trace to the console
     LOG.log(Level.SEVERE, "unexpected error", e);
   }
   return localizedMessage;
 }
  private void processException(Throwable e) {
    if (e.getMessage() != null) {
      myProgress.addMessage(myDebuggerSession, MessageCategory.ERROR, e.getMessage());
    }

    if (e instanceof ProcessCanceledException) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.INFORMATION,
          DebuggerBundle.message("error.operation.canceled"));
      return;
    }

    if (e instanceof UnsupportedOperationException) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.ERROR,
          DebuggerBundle.message("error.operation.not.supported.by.vm"));
    } else if (e instanceof NoClassDefFoundError) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.ERROR,
          DebuggerBundle.message("error.class.def.not.found", e.getLocalizedMessage()));
    } else if (e instanceof VerifyError) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.ERROR,
          DebuggerBundle.message("error.verification.error", e.getLocalizedMessage()));
    } else if (e instanceof UnsupportedClassVersionError) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.ERROR,
          DebuggerBundle.message("error.unsupported.class.version", e.getLocalizedMessage()));
    } else if (e instanceof ClassFormatError) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.ERROR,
          DebuggerBundle.message("error.class.format.error", e.getLocalizedMessage()));
    } else if (e instanceof ClassCircularityError) {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.ERROR,
          DebuggerBundle.message("error.class.circularity.error", e.getLocalizedMessage()));
    } else {
      myProgress.addMessage(
          myDebuggerSession,
          MessageCategory.ERROR,
          DebuggerBundle.message(
              "error.exception.while.reloading", e.getClass().getName(), e.getLocalizedMessage()));
    }
  }
  private boolean loadWebPage(final JWebBrowser webBrowser) {
    try {
      final String language = Locale.getDefault().getLanguage();
      File html =
          Externalization.extractFile(
              "slash/navigation/converter/gui/mapview/routeconverter.html",
              language,
              new TokenResolver() {
                public String resolveToken(String tokenName) {
                  if (tokenName.equals("locale")) return language;
                  if (tokenName.equals("percent")) return Platform.isWindows() ? "99" : "100";
                  if (tokenName.equals("mapserver"))
                    return preferences.get(MAP_SERVER_PREFERENCE, "maps.google.com");
                  return tokenName;
                }
              });
      if (html == null) throw new IllegalArgumentException("Cannot extract routeconverter.html");
      Externalization.extractFile("slash/navigation/converter/gui/mapview/contextmenucontrol.js");

      final String url = html.toURI().toURL().toExternalForm();
      webBrowser.runInSequence(
          new Runnable() {
            public void run() {
              webBrowser.navigate(url);
            }
          });
      log.fine(System.currentTimeMillis() + " loadWebPage thread " + Thread.currentThread());
    } catch (Throwable t) {
      log.severe("Cannot create WebBrowser: " + t.getMessage());
      setInitializationCause(t);
      return false;
    }
    return true;
  }
    public void actionPerformed(ActionEvent e) {
      try {
        MockResult mockResult = mockResponse.getMockResult();
        mockResponse.evaluateScript(mockResult == null ? null : mockResult.getMockRequest());

        StringToStringMap values = null;
        if (mockResponse.getMockResult() != null) {
          values = mockResponse.getMockResult().getMockRequest().getContext().toStringToStringMap();
        }

        if (values == null || values.isEmpty()) {
          UISupport.showInfoMessage("No values were returned");
        } else {
          String msg = "<html><body>Returned values:<br>";

          for (String name : values.keySet()) {
            msg += XmlUtils.entitize(name) + " : " + XmlUtils.entitize(values.get(name)) + "<br>";
          }

          msg += "</body></html>";

          UISupport.showExtendedInfo(
              "Result", "Result of MockResponse Script", msg, new Dimension(500, 400));
        }
      } catch (Throwable e1) {
        responseScriptEditor.selectError(e1.getMessage());
        UISupport.showErrorMessage(e1.toString());
      }
    }
 private void logTrace(StringBuilder builder, Throwable e) {
   Throwable parent = e;
   String indent = "    ";
   while (parent != null) {
     if (parent == e) {
       builder.append(indent).append("Trace:").append("\n");
     } else {
       builder
           .append(indent)
           .append("Caused By: (")
           .append(parent.getClass().getSimpleName())
           .append(")")
           .append("\n");
       builder
           .append(indent)
           .append("    ")
           .append("[")
           .append(parent.getMessage())
           .append("]")
           .append("\n");
     }
     for (StackTraceElement ele : e.getStackTrace()) {
       builder.append(indent).append("    ").append(ele.toString()).append("\n");
     }
     indent += "    ";
     parent = parent.getCause();
   }
 }
 public void actionPerformed(ActionEvent e) {
   try {
     String scannedDestination = ((JTextField) e.getSource()).getText().toUpperCase();
     validateDestinationScan(scannedDestination);
     DefaultListModel listModel = (DefaultListModel) destinationsList.getModel();
     int lastPosition = listModel.getSize();
     int seedsCount = 0;
     // todo: do we have to worry about more trays than required..?
     for (int i = 0; i < seedPlates.length; i++) {
       if (seedPlates[i].getSeedPlateBarcode() != null
           && SCANNED.equals(seedPlates[i].getStatus())
           && !isContainedInList(seedPlates[i].getSeedPlateBarcode(), failedPlatesList)) {
         seedsCount++;
       }
     }
     if (lastPosition >= seedsCount) {
       throw new ChippingManagerException(DESTINATIONS_LIMIT_EXCEEDED);
     }
     addDestination(scannedDestination);
   } catch (Throwable cmException) {
     logger.error("Unable to scan destination ", cmException);
     JOptionPane.showMessageDialog(
         new JFrame(),
         cmException.getMessage(),
         TITLE_CHIPPING_MANAGER,
         JOptionPane.WARNING_MESSAGE);
   }
   scanDestination.setText(BLANK);
 }
 @Override
 public void processPacket(Packet packet) {
   try {
     doProcessPacket(packet);
   } catch (Throwable e) {
     LOG.error(e.getMessage(), e);
   }
 }
 private void populateException(Throwable e) {
   StringBuilder builder = new StringBuilder();
   builder.append("Stack Trace:").append("\n");
   builder.append("    Exception: ").append(e.getClass().getSimpleName()).append("\n");
   builder.append("    Message: ").append(e.getMessage()).append("\n");
   logTrace(builder, e);
   errorArea.setText(builder.toString());
 }
 public void actionPerformed(ActionEvent e) {
   try {
     validateUnloadPlatesDialog();
     unloadPlates();
   } catch (Throwable cmException) {
     logger.error("error to unload to multiple destinations", cmException);
     JOptionPane.showMessageDialog(
         new JFrame(),
         cmException.getMessage(),
         TITLE_CHIPPING_MANAGER,
         JOptionPane.WARNING_MESSAGE);
   }
 }
 private String generateExceptionReport() {
   StringBuilder builder = new StringBuilder("Spoutcraft Launcher Error Report:\n");
   builder.append("( Please submit this report to http://spout.in/issues )\n");
   builder.append("    Launcher Build: ").append(Settings.getLauncherBuild()).append("\n");
   builder
       .append("----------------------------------------------------------------------")
       .append("\n");
   builder.append("Stack Trace:").append("\n");
   builder.append("    Exception: ").append(cause.getClass().getSimpleName()).append("\n");
   builder.append("    Message: ").append(cause.getMessage()).append("\n");
   logTrace(builder, cause);
   builder
       .append("----------------------------------------------------------------------")
       .append("\n");
   builder.append("System Information:\n");
   builder.append("    Operating System: ").append(System.getProperty("os.name")).append("\n");
   builder
       .append("    Operating System Version: ")
       .append(System.getProperty("os.version"))
       .append("\n");
   builder
       .append("    Operating System Architecture: ")
       .append(System.getProperty("os.arch"))
       .append("\n");
   builder
       .append("    Java version: ")
       .append(System.getProperty("java.version"))
       .append(" ")
       .append(System.getProperty("sun.arch.data.model", "32"))
       .append(" bit")
       .append("\n");
   builder
       .append("    Total Memory: ")
       .append(Runtime.getRuntime().totalMemory() / 1024L / 1024L)
       .append(" MB\n");
   builder
       .append("    Max Memory: ")
       .append(Runtime.getRuntime().maxMemory() / 1024L / 1024L)
       .append(" MB\n");
   builder
       .append("    Memory Free: ")
       .append(Runtime.getRuntime().freeMemory() / 1024L / 1024L)
       .append(" MB\n");
   builder
       .append("    CPU Cores: ")
       .append(Runtime.getRuntime().availableProcessors())
       .append("\n");
   return builder.toString();
 }
 @Override
 protected void done() {
   super.done();
   try {
     this.get();
     listener.done();
   } catch (InterruptedException e) {
     listener.setStatus("Interrupted Exception: " + e.getMessage());
     e.printStackTrace(new PrintStream(callbacks.getStderr()));
   } catch (ExecutionException e) {
     listener.setStatus("Execution Exception: " + e.getMessage());
     e.printStackTrace(new PrintStream(callbacks.getStderr()));
   } catch (Throwable e) {
     listener.setStatus(e.getMessage());
     e.printStackTrace(new PrintStream(callbacks.getStderr()));
   }
 }
 @Override
 protected void handleInitComponentError(
     final Throwable ex, final boolean fatal, final String componentClassName) {
   if (PluginManager.isPluginClass(componentClassName)) {
     LOG.error(ex);
     PluginId pluginId = PluginManager.getPluginByClassName(componentClassName);
     @NonNls
     final String errorMessage =
         "Plugin "
             + pluginId.getIdString()
             + " failed to initialize and will be disabled:\n"
             + ex.getMessage()
             + "\nPlease restart "
             + ApplicationNamesInfo.getInstance().getFullProductName()
             + ".";
     PluginManager.disablePlugin(pluginId.getIdString());
     if (!myHeadlessMode) {
       JOptionPane.showMessageDialog(null, errorMessage);
     } else {
       //noinspection UseOfSystemOutOrSystemErr
       System.out.println(errorMessage);
       System.exit(1);
     }
     return; // do not call super
   }
   if (fatal) {
     LOG.error(ex);
     @NonNls
     final String errorMessage =
         "Fatal error initializing class "
             + componentClassName
             + ":\n"
             + ex.toString()
             + "\nComplete error stacktrace was written to idea.log";
     if (!myHeadlessMode) {
       JOptionPane.showMessageDialog(null, errorMessage);
     } else {
       //noinspection UseOfSystemOutOrSystemErr
       System.out.println(errorMessage);
     }
   }
   super.handleInitComponentError(ex, fatal, componentClassName);
 }
Beispiel #13
0
  public void setData(String text) {
    if (text != null && text.length() > 0) {
      InputStream in = null;
      try {
        Object result = null;
        Drawing drawing = createDrawing();
        // Try to read the data using all known input formats.
        for (InputFormat fmt : drawing.getInputFormats()) {
          try {
            fmt.read(in, drawing);
            in = new ByteArrayInputStream(text.getBytes("UTF8"));
            result = drawing;
            break;
          } catch (IOException e) {
            result = e;
          }
        }
        if (result instanceof IOException) {
          throw (IOException) result;
        }

        setDrawing(drawing);
      } catch (Throwable e) {
        getDrawing().removeAllChildren();
        SVGTextFigure tf = new SVGTextFigure();
        tf.setText(e.getMessage());
        tf.setBounds(new Point2D.Double(10, 10), new Point2D.Double(100, 100));
        getDrawing().add(tf);
        e.printStackTrace();
      } finally {
        if (in != null) {
          try {
            in.close();
          } catch (IOException ex) {
            ex.printStackTrace();
          }
        }
      }
    }
  }
 private JWebBrowser createWebBrowser() {
   try {
     if (!NativeInterface.isOpen()) throw new Exception("Native Interface is not initialized");
     JWebBrowser browser;
     if (Platform.isLinux()) {
       if (Platform.is64Bit()) {
         try {
           System.setProperty("org.eclipse.swt.browser.UseWebKitGTK", "true");
           // System.setProperty("nativeswing.webbrowser.runtime", "webkit");
           browser = new JWebBrowser(JWebBrowser.useWebkitRuntime());
           log.info("Using WebKit runtime to create WebBrowser");
         } catch (IllegalStateException e) {
           System.clearProperty("org.eclipse.swt.browser.UseWebKitGTK");
           browser = new JWebBrowser(JWebBrowser.useXULRunnerRuntime());
           log.info("Using XULRunner runtime to create WebBrowser: " + e.getMessage());
         }
       } else {
         try {
           System.setProperty("org.eclipse.swt.browser.UseWebKitGTK", "true");
           browser = new JWebBrowser(JWebBrowser.useWebkitRuntime());
           log.info("Using WebKit runtime to create WebBrowser");
         } catch (IllegalStateException e) {
           System.clearProperty("org.eclipse.swt.browser.UseWebKitGTK");
           browser = new JWebBrowser(JWebBrowser.useXULRunnerRuntime());
           log.info("Using XULRunner runtime to create WebBrowser: " + e.getMessage());
         }
       }
     } else {
       browser = new JWebBrowser();
     }
     browser.setBarsVisible(false);
     browser.setJavascriptEnabled(true);
     return browser;
   } catch (Throwable t) {
     log.severe("Cannot create WebBrowser: " + t.getMessage());
     setInitializationCause(t);
     return null;
   }
 }
 /**
  * Default action when any uncaught exception bubbled from the mouse event handlers of the tools.
  * Subclass may override it to provide other action.
  */
 protected void handleMouseEventException(Throwable t) {
   JOptionPane.showMessageDialog(
       this, t.getClass().getName() + " - " + t.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
   t.printStackTrace();
 }
  /**
   * Creates an account for the given user and password.
   *
   * @param providerFactory the ProtocolProviderFactory which will create the account
   * @param userName the user identifier
   * @param passwd the password
   * @return the <tt>ProtocolProviderService</tt> for the new account.
   * @throws OperationFailedException if the operation didn't succeed
   */
  protected ProtocolProviderService installAccount(
      ProtocolProviderFactory providerFactory, String userName, String passwd)
      throws OperationFailedException {
    if (logger.isTraceEnabled()) {
      logger.trace("Preparing to install account for user " + userName);
    }
    Hashtable<String, String> accountProperties = new Hashtable<String, String>();

    String protocolIconPath = getProtocolIconPath();

    String accountIconPath = getAccountIconPath();

    registration.storeProperties(
        userName, passwd, protocolIconPath, accountIconPath, accountProperties);

    accountProperties.put(
        ProtocolProviderFactory.IS_PREFERRED_PROTOCOL, Boolean.toString(isPreferredProtocol()));
    accountProperties.put(ProtocolProviderFactory.PROTOCOL, getProtocol());

    if (isModification()) {
      providerFactory.modifyAccount(protocolProvider, accountProperties);

      setModification(false);

      return protocolProvider;
    }

    try {
      if (logger.isTraceEnabled()) {
        logger.trace(
            "Will install account for user "
                + userName
                + " with the following properties."
                + accountProperties);
      }

      AccountID accountID = providerFactory.installAccount(userName, accountProperties);

      ServiceReference serRef = providerFactory.getProviderForAccount(accountID);

      protocolProvider =
          (ProtocolProviderService) JabberAccRegWizzActivator.bundleContext.getService(serRef);
    } catch (IllegalArgumentException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Username, password or server is null.", OperationFailedException.ILLEGAL_ARGUMENT);
    } catch (IllegalStateException exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Account already exists.", OperationFailedException.IDENTIFICATION_CONFLICT);
    } catch (Throwable exc) {
      logger.warn(exc.getMessage());

      throw new OperationFailedException(
          "Failed to add account.", OperationFailedException.GENERAL_ERROR);
    }

    return protocolProvider;
  }