java.lang.Exception.addSuppressed()方法的使用及代码示例

x33g5p2x  于2022-01-16 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(270)

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

Exception.addSuppressed介绍

暂无

代码示例

代码示例来源:origin: prestodb/presto

private static void addSuppressed(Exception exception, List<Throwable> suppressedExceptions)
  {
    for (Throwable suppressedException : suppressedExceptions) {
      if (exception != suppressedException) {
        exception.addSuppressed(suppressedException);
      }
    }
  }
}

代码示例来源:origin: prestodb/presto

private static void addSuppressed(Exception exception, List<Throwable> suppressedExceptions)
  {
    for (Throwable suppressedException : suppressedExceptions) {
      if (exception != suppressedException) {
        exception.addSuppressed(suppressedException);
      }
    }
  }
}

代码示例来源:origin: prestodb/presto

public void addSuppressed(Throwable throwable)
  {
    checkState(exception != null, "exception is null");
    checkArgument(throwable != null, "throwable is null");
    exception.addSuppressed(throwable);
  }
}

代码示例来源:origin: wildfly/wildfly

@SuppressWarnings("unchecked")
void addRollbackExceptions(Exception ex) {
  List<Throwable> list = (List<Throwable>) getResource(RB_EX_KEY);
  if (list != null) {
    for (Throwable throwable : list) {
      ex.addSuppressed(throwable);
    }
  }
}

代码示例来源:origin: apache/ignite

/**
   * @param err Error.
   */
  private void addError(Throwable err) {
    Exception ex = errCollector.get();

    if (ex == null) {
      Exception compound = new IgniteCheckedException("Compound exception for CountDownFuture.");

      ex = errCollector.compareAndSet(null, compound) ? compound : errCollector.get();
    }

    assert ex != null;

    ex.addSuppressed(err);
  }
}

代码示例来源:origin: prestodb/presto

private RuntimeException handleSqlException(Exception e)
  {
    try {
      close();
    }
    catch (Exception closeException) {
      // Self-suppression not permitted
      if (e != closeException) {
        e.addSuppressed(closeException);
      }
    }
    return new PrestoException(JDBC_ERROR, e);
  }
}

代码示例来源:origin: apache/incubator-druid

private void delegateToAllChildren(RequestLogLine requestLogLine, RequestLogLineConsumer consumer) throws IOException
{
 Exception exception = null;
 for (RequestLogger logger : loggers) {
  try {
   consumer.accept(logger, requestLogLine);
  }
  catch (Exception e) {
   if (exception == null) {
    exception = e;
   } else {
    exception.addSuppressed(e);
   }
  }
 }
 if (exception != null) {
  Throwables.propagateIfInstanceOf(exception, IOException.class);
  throw Throwables.propagate(exception);
 }
}

代码示例来源:origin: neo4j/neo4j

private void closeAndThrow( Exception e )
{
  if ( pagedFile != null )
  {
    try
    {
      closeStoreFile();
    }
    catch ( IOException failureToClose )
    {
      // Not really a suppressed exception, but we still want to throw the real exception, e,
      // but perhaps also throw this in there or convenience.
      e.addSuppressed( failureToClose );
    }
  }
  throwIfUnchecked( e );
  throw new RuntimeException( e );
}

代码示例来源:origin: apache/ignite

/**
   * @param ex Exception holder.
   * @param e Exception.
   */
  private void onException(AtomicReference<Exception> ex, Exception e) {
    if (!ex.compareAndSet(null, e))
      ex.get().addSuppressed(e);
  }
}

代码示例来源:origin: apache/ignite

/**
 * @param exHldr Exception holder.
 * @param ex Exception.
 */
private void addException(AtomicReference<Exception> exHldr, Exception ex) {
  if (exHldr.get() != null || !exHldr.compareAndSet(null, ex))
    exHldr.get().addSuppressed(ex);
}

代码示例来源:origin: redisson/redisson

/**
 * Helper method that encapsulate logic in trying to close output generator
 * in case of failure; useful mostly in forcing flush()ing as otherwise
 * error conditions tend to be hard to diagnose. However, it is often the
 * case that output state may be corrupt so we need to be prepared for
 * secondary exception without masking original one.
 *
 * @since 2.8
 */
public static void closeOnFailAndThrowAsIOE(JsonGenerator g, Exception fail)
  throws IOException
{
  /* 04-Mar-2014, tatu: Let's try to prevent auto-closing of
   *    structures, which typically causes more damage.
   */
  g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
  try {
    g.close();
  } catch (Exception e) {
    fail.addSuppressed(e);
  }
  throwIfIOE(fail);
  throwIfRTE(fail);
  throw new RuntimeException(fail);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

/**
 * Tests LOG4J2-934.
 */
@Test
public void testCircularSuppressedNestedException() {
  final Exception e1 = new Exception();
  final Exception e2 = new Exception(e1);
  e2.addSuppressed(e1);
  e1.addSuppressed(e2);
  LogManager.getLogger().error("Error", e1);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

/**
 * Tests LOG4J2-934.
 */
@Test
public void testCircularSuppressedExceptions() {
  final Exception e1 = new Exception();
  final Exception e2 = new Exception();
  e2.addSuppressed(e1);
  e1.addSuppressed(e2);
  LogManager.getLogger().error("Error", e1);
}

代码示例来源:origin: SonarSource/sonarqube

private void finalizeTask(CeTask task, Profiler ceProfiler, CeActivityDto.Status status,
 @Nullable CeTaskResult taskResult, @Nullable Throwable error) {
 try {
  queue.remove(task, status, taskResult, error);
 } catch (Exception e) {
  if (error != null) {
   e.addSuppressed(error);
  }
  LOG.error(format("Failed to finalize task with uuid '%s' and persist its state to db", task.getUuid()), e);
 } finally {
  // finalize
  stopLogProfiler(ceProfiler, status);
  callListeners(t -> t.onEnd(task, status, taskResult, error));
 }
}

代码示例来源:origin: prestodb/presto

/**
 * Helper method that encapsulate logic in trying to close output generator
 * in case of failure; useful mostly in forcing flush()ing as otherwise
 * error conditions tend to be hard to diagnose. However, it is often the
 * case that output state may be corrupt so we need to be prepared for
 * secondary exception without masking original one.
 *
 * @since 2.8
 */
public static void closeOnFailAndThrowAsIOE(JsonGenerator g, Exception fail)
  throws IOException
{
  /* 04-Mar-2014, tatu: Let's try to prevent auto-closing of
   *    structures, which typically causes more damage.
   */
  g.disable(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT);
  try {
    g.close();
  } catch (Exception e) {
    fail.addSuppressed(e);
  }
  throwIfIOE(fail);
  throwIfRTE(fail);
  throw new RuntimeException(fail);
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testCauseSuppressedExceptions() {
  final Exception cause = new Exception("Nested exception");
  cause.addSuppressed(new IOException("Suppressed #1"));
  cause.addSuppressed(new IOException("Suppressed #2"));
  LogManager.getLogger().error("Error", new Exception(cause));
  final ThrowableProxy proxy = new ThrowableProxy(new Exception("Root exception", cause));
  final String extendedStackTraceAsString = proxy.getExtendedStackTraceAsString("same suffix");
  assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1"));
  assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1"));
}

代码示例来源:origin: apache/incubator-druid

@Nullable
private Exception getDeadlockedThreadsException()
{
 final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
 final long[] deadlockedThreadIds = threadMXBean.findDeadlockedThreads();
 if (deadlockedThreadIds == null) {
  return null;
 }
 Exception deadlockException = new Exception("Deadlocked threads:");
 for (long deadlockedThreadId : deadlockedThreadIds) {
  ThreadInfo threadInfo = threadMXBean.getThreadInfo(deadlockedThreadId);
  Exception threadException = new Exception(threadInfo.getThreadName() + " at " + threadInfo.getLockName());
  threadException.setStackTrace(threadInfo.getStackTrace());
  deadlockException.addSuppressed(threadException);
 }
 return deadlockException;
}

代码示例来源:origin: org.apache.logging.log4j/log4j-core

@Test
public void testSuppressedExceptions() {
  final Exception e = new Exception("Root exception");
  e.addSuppressed(new IOException("Suppressed #1"));
  e.addSuppressed(new IOException("Suppressed #2"));
  LogManager.getLogger().error("Error", e);
  final ThrowableProxy proxy = new ThrowableProxy(e);
  final String extendedStackTraceAsString = proxy.getExtendedStackTraceAsString("same suffix");
  assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1"));
  assertTrue(extendedStackTraceAsString.contains("\tSuppressed: java.io.IOException: Suppressed #1"));
}

代码示例来源:origin: neo4j/neo4j

private StoreLocker tryLockStore( FileSystemAbstraction fileSystem )
{
  StoreLocker storeLocker = new GlobalStoreLocker( fileSystem, this.databaseLayout.getStoreLayout() );
  try
  {
    storeLocker.checkLock();
  }
  catch ( Exception e )
  {
    try
    {
      storeLocker.close();
    }
    catch ( IOException ce )
    {
      e.addSuppressed( ce );
    }
    throw e;
  }
  return storeLocker;
}

代码示例来源:origin: apache/incubator-druid

public static class TaskNotRunnableException extends RuntimeException
{
 public TaskNotRunnableException(String message)
 {
  super(message);
 }
}

相关文章