com.yahoo.yolean.Exceptions类的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(5.7k)|赞(0)|评价(0)|浏览(118)

本文整理了Java中com.yahoo.yolean.Exceptions类的一些代码示例,展示了Exceptions类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Exceptions类的具体详情如下:
包路径:com.yahoo.yolean.Exceptions
类名称:Exceptions

Exceptions介绍

[英]Helper methods for handling exceptions
[中]处理异常的Helper方法

代码示例

代码示例来源:origin: com.yahoo.vespa/container-search

private void logWarning(String attemptDescription, Exception e) {
  log.log(Level.WARNING, "Exception on " + attemptDescription + " '" + host + ":" + port + "': " + Exceptions.toMessageString(e));
}

代码示例来源:origin: com.yahoo.vespa/yolean

/**
 * <p>Returns a user friendly error message string which includes information from all nested exceptions.</p>
 *
 * <p>The form of this string is
 * <code>e.getMessage(): e.getCause().getMessage(): e.getCause().getCause().getMessage()...</code>
 * In addition, some heuristics are used to clean up common cases where exception nesting causes bad messages.
 */
public static String toMessageString(Throwable t) {
  StringBuilder b = new StringBuilder();
  String lastMessage = null;
  String message;
  for (; t != null; t = t.getCause()) {
    message = getMessage(t);
    if (message == null) continue;
    if (message.equals(lastMessage)) continue;
    if (b.length() > 0) {
      b.append(": ");
    }
    b.append(message);
    lastMessage = message;
  }
  return b.toString();
}

代码示例来源:origin: com.yahoo.vespa/flags

public JsonNode serializeToJsonNode() {
  return uncheck(() -> mapper.valueToTree(this));
}

代码示例来源:origin: com.yahoo.vespa/application

private Application build() throws Exception {
  Application app = null;
  Exception exception = null;
  // if we get a bind exception, then retry a few times (may conflict with parallel test runs)
  for (int i = 0; i < 5; i++) {
    try {
      generateXml();
      app = new Application(path, networking, true);
      break;
    } catch (Error e) { // the container thinks this is really serious, in this case is it not in the cause is a BindException
      // catch bind error and reset container
      Optional<BindException> bindException = Exceptions.findCause(e, BindException.class);
      if (bindException.isPresent()) {
        exception = bindException.get();
        com.yahoo.container.Container.resetInstance(); // this is needed to be able to recreate the container from config again
      } else {
        throw new Exception(e.getCause());
      }
    }
  }
  if (app == null) {
    throw exception;
  }
  return app;
}

代码示例来源:origin: com.yahoo.vespa/container-search

private void logInfo(String attemptDescription, Exception e) {
  log.log(Level.INFO, "Exception on " + attemptDescription + " '" + host + ":" + port + "': " + Exceptions.toMessageString(e));
}

代码示例来源:origin: com.yahoo.vespa/flags

public static WireFlagDataList deserializeFrom(byte[] bytes) {
    return uncheck(() -> mapper.readValue(bytes, WireFlagDataList.class));
  }
}

代码示例来源:origin: com.yahoo.vespa/container-core

@Override
  public void failed(Throwable t) {
    Level logLevel;
    synchronized (failLock) {
      if (failed) {
        logLevel = LogLevel.SPAM;
      } else {
        logLevel = LogLevel.DEBUG;
      }
      failed = true;
    }
    if (log.isLoggable(logLevel)) {
      log.log(logLevel, "Got exception when writing to client: " + Exceptions.toMessageString(t));
    }
  }
}

代码示例来源:origin: com.yahoo.vespa/flags

public void serializeToOutputStream(OutputStream outputStream) {
  uncheck(() -> mapper.writeValue(outputStream, this));
}

代码示例来源:origin: com.yahoo.vespa/vespajlib

@Override
public String toString() {
  String details = "";
  if (detailedMessage != null) {
    details = detailedMessage;
  }
  if (cause !=null) {
    if (details.length()>0)
      details+=": ";
    details+= com.yahoo.yolean.Exceptions.toMessageString(cause);
  }
  if (details.length()>0)
    details=" (" + details + ")";
  return "error : " + message + details;
}

代码示例来源:origin: com.yahoo.vespa/flags

public static WireFlagData deserialize(String string) {
  return uncheck(() -> mapper.readValue(string, WireFlagData.class));
}

代码示例来源:origin: com.yahoo.vespa/container-core

@Override
public void failed(Throwable throwable) {
  long endTime = System.currentTimeMillis();
  writeToLogs(endTime);
  if (log.isLoggable(LogLevel.DEBUG)) {
    log.log(LogLevel.DEBUG, "Got exception when writing to client: " + Exceptions.toMessageString(throwable));
  }
}

代码示例来源:origin: com.yahoo.vespa/flags

private void writeFile(byte[] bytes) {
    uncheck(() -> Files.createDirectories(path.getParent()));
    uncheck(() -> Files.write(path, bytes));
  }
}

代码示例来源:origin: com.yahoo.vespa/container-core

/**
 * Flush the internal buffers, does not touch the ContentChannel.
 */
@Override
public void flush() throws IOException {
  try {
    buffer.flush();
  } catch (RuntimeException e) {
    throw new IOException(Exceptions.toMessageString(e), e);
  }
}

代码示例来源:origin: com.yahoo.vespa/flags

public static WireFlagData deserialize(InputStream inputStream) {
    return uncheck(() -> mapper.readValue(inputStream, WireFlagData.class));
  }
}

代码示例来源:origin: com.yahoo.vespa/config-model

private void validateWarn(Exception e, DeployLogger deployLogger) {
  String msg = "Unable to execute 'vespa-verify-ranksetup', validation of rank expressions will only take place when you start Vespa: " +
      Exceptions.toMessageString(e);
  deployLogger.log(LogLevel.WARNING, msg);
}

代码示例来源:origin: com.yahoo.vespa/flags

public void serializeToOutputStream(OutputStream outputStream) {
  uncheck(() -> mapper.writeValue(outputStream, this));
}

代码示例来源:origin: com.yahoo.vespa/container-search

private ErrorMessage createExecutionError(Exception e) {
  log.log(Level.WARNING,"Exception on executing " + execution + " for " + query,e);
  return ErrorMessage.createErrorInPluginSearcher("Error in '" + execution + "': " + Exceptions.toMessageString(e),
                          e.getCause());
}

代码示例来源:origin: com.yahoo.vespa/flags

public static WireFlagData deserialize(byte[] bytes) {
  return uncheck(() -> mapper.readValue(bytes, WireFlagData.class));
}

代码示例来源:origin: com.yahoo.vespa/container-core

/**
 * Buffered write of a single byte.
 */
@Override
public void write(final int b) throws IOException {
  try {
    buffer.append((byte) b);
  } catch (RuntimeException e) {
    throw new IOException(Exceptions.toMessageString(e), e);
  }
}

代码示例来源:origin: com.yahoo.vespa/flags

public byte[] serializeToBytes() {
  return uncheck(() -> mapper.writeValueAsBytes(this));
}

相关文章

Exceptions类方法