@Override
  public void finishCommand(final @NotNull CommandToken command, final @Nullable Throwable throwable) {
    if (myCurrentCommand != command) return;
    final boolean failed;
    try {
      if (throwable != null) {
        failed = true;
        if (!(throwable instanceof ProcessCanceledException)) {
          ExceptionUtil.rethrowUnchecked(throwable);
          CommandLog.LOG.error(throwable);
        }
      }
      else {
        failed = false;
      }
    }
    finally {
      try {
        super.finishCommand(command, throwable);
      }
      catch (Throwable e) {
        if (throwable != null && throwable != e) {
          e.addSuppressed(throwable);
        }
        throw e;
      }
    }
    if (failed) {
      Project project = command.getProject();
      if (project != null) {
        FileEditor editor = new FocusBasedCurrentEditorProvider().getCurrentEditor(project);
        final UndoManager undoManager = UndoManager.getInstance(project);
        if (undoManager.isUndoAvailable(editor)) {
          undoManager.undo(editor);
        }
      }
      if (!(throwable instanceof ProcessCanceledException)) {
        Messages.showErrorDialog(project, IdeBundle.message("dialog.message.cannot.perform.operation.too.complex.sorry"),
                                 IdeBundle.message("dialog.title.failed.to.perform.operation"));
      }
    }
  }
@Override
  public void finishCommand(final @NotNull CommandToken command, final @Nullable Throwable throwable)