Java Code Examples for com.intellij.util.ExceptionUtil#getRootCause()

The following examples show how to use com.intellij.util.ExceptionUtil#getRootCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Log4J2DialogAppender.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Nonnull
private static IdeaLoggingEvent extractLoggingEvent(@Nonnull Message message, @Nonnull Throwable throwable) {
  //noinspection ThrowableResultOfMethodCallIgnored
  Throwable rootCause = ExceptionUtil.getRootCause(throwable);
  if (rootCause instanceof LogEventException) {
    return ((LogEventException)rootCause).getLogMessage();
  }

  String strMessage = message.getFormattedMessage();
  ExceptionWithAttachments withAttachments = ExceptionUtil.findCause(throwable, ExceptionWithAttachments.class);
  if (withAttachments != null) {
    return LogMessageEx.createEvent(strMessage, ExceptionUtil.getThrowableText(throwable), withAttachments.getAttachments());
  }

  return new IdeaLoggingEvent(strMessage, throwable);
}
 
Example 2
Source File: ConsoleHistoryController.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean loadHistoryOld(String id) {
  File file = new File(PathUtil.toSystemDependentName(getOldHistoryFilePath(id)));
  if (!file.exists()) return false;
  try {
    Element rootElement = JDOMUtil.load(file);
    String text = loadHistory(rootElement, id);
    if (text != null) {
      myContent = text;
      return true;
    }
  }
  catch (Exception ex) {
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable cause = ExceptionUtil.getRootCause(ex);
    if (cause instanceof EOFException) {
      LOG.warn("Failed to load " + myRootType.getId() + " history from: " + file.getPath(), ex);
      return false;
    }
    else {
      LOG.error(ex);
    }
  }
  return false;
}
 
Example 3
Source File: RunIdeConsoleAction.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static void executeQuery(@Nonnull Project project, @Nonnull VirtualFile file, @Nonnull Editor editor, @Nonnull IdeScriptEngine engine) {
  String command = getCommandText(project, editor);
  if (StringUtil.isEmptyOrSpaces(command)) return;
  String profile = getProfileText(file);
  RunContentDescriptor descriptor = getConsoleView(project, file);
  ConsoleViewImpl consoleView = (ConsoleViewImpl)descriptor.getExecutionConsole();

  prepareEngine(project, engine, descriptor);
  try {
    long ts = System.currentTimeMillis();
    //myHistoryController.getModel().addToHistory(command);
    consoleView.print("> " + command, ConsoleViewContentType.USER_INPUT);
    consoleView.print("\n", ConsoleViewContentType.USER_INPUT);
    String script = profile == null ? command : profile + "\n" + command;
    Object o = engine.eval(script);
    String prefix = "[" + (StringUtil.formatDuration(System.currentTimeMillis() - ts)) + "]";
    consoleView.print(prefix + "=> " + o, ConsoleViewContentType.NORMAL_OUTPUT);
    consoleView.print("\n", ConsoleViewContentType.NORMAL_OUTPUT);
  }
  catch (Throwable e) {
    //noinspection ThrowableResultOfMethodCallIgnored
    Throwable ex = ExceptionUtil.getRootCause(e);
    consoleView.print(ex.getClass().getSimpleName() + ": " + ex.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
    consoleView.print("\n", ConsoleViewContentType.ERROR_OUTPUT);
  }
  selectContent(descriptor);
}