java.lang.RuntimeException.getSuppressed()方法的使用及代码示例

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

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

RuntimeException.getSuppressed介绍

暂无

代码示例

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

@Test
void shouldThrowAppropriateExceptionIfBothStartAndShutdownFail()
{
  RuntimeException startupError = new RuntimeException();
  RuntimeException shutdownError = new RuntimeException();
  GraphDatabaseFacadeFactory db = newFaultyGraphDatabaseFacadeFactory( startupError );
  doThrow( shutdownError ).when( mockFacade ).shutdown();
  RuntimeException initException =
      assertThrows( RuntimeException.class, () -> db.initFacade( testDirectory.storeDir(), Collections.emptyMap(), deps, mockFacade ) );
  assertTrue( initException.getMessage().startsWith( "Error starting " ) );
  assertEquals( startupError, initException.getCause() );
  assertEquals( shutdownError, initException.getSuppressed()[0] );
}

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

@Test
public void testRollbackThrow() throws Exception {
  RuntimeException outer = new RuntimeException("Transaction throws!");
  RuntimeException inner = new RuntimeException("Rollback throws!");
  Mockito.when(c.getAutoCommit()).thenReturn(true);
  Mockito.when(h.getConnection()).thenReturn(c);
  Mockito.when(h.rollback()).thenThrow(inner);
  try {
    new LocalTransactionHandler().inTransaction(h, x -> {
      throw outer;
    });
  } catch (RuntimeException e) {
    assertThat(e).isSameAs(outer);
    assertThat(e.getSuppressed()).hasSize(1);
    assertThat(e.getSuppressed()[0]).isSameAs(inner);
  }
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void throwTwoRuntimeExceptions() throws Throwable {
 Exception bdcException = new IllegalStateException("block deletion context exception");
 Exception jcException = new IllegalArgumentException("journal context exception");
 doThrow(bdcException).when(mMockBDC).close();
 doThrow(jcException).when(mMockJC).close();
 try {
  mRpcContext.close();
  fail("Expected an exception to be thrown");
 } catch (RuntimeException e) {
  assertEquals(jcException, e);
  // journal context is closed first, so the block deletion context exception should be
  // suppressed.
  assertEquals(bdcException, e.getSuppressed()[0]);
 }
}

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

assertTrue( failed.hasNext() );
assertEquals( e.getMessage(), failed.next() );
for ( Throwable suppressed : e.getSuppressed() )

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

if (closeError.getSuppressed().length > 0) {
  throw closeError;

代码示例来源:origin: io.ratpack/ratpack-core

private static ImmutableSet<ConfigObject<?>> extractRequiredConfig(ConfigData configData, Map<String, TypeToken<?>> required) {
 RuntimeException badConfig = new IllegalStateException("Failed to build required config items");
 ImmutableSet.Builder<ConfigObject<?>> config = ImmutableSet.builder();
 for (Map.Entry<String, TypeToken<?>> requiredConfig : required.entrySet()) {
  String path = requiredConfig.getKey();
  TypeToken<?> type = requiredConfig.getValue();
  try {
   config.add(configData.getAsConfigObject(path, type));
  } catch (Exception e) {
   badConfig.addSuppressed(new IllegalStateException("Could not bind config at '" + path + "' to '" + type + "'", e));
  }
 }
 if (badConfig.getSuppressed().length > 0) {
  throw badConfig;
 } else {
  return config.build();
 }
}

代码示例来源:origin: reactor/reactive-streams-commons

/**
 * Loops through all values in the set and collects any exceptions from the consumer
 * into a Throwable.
 * @param consumer the consumer to call
 * @return if not null, contains a CompositeException with all the suppressed exceptions
 */
public Throwable forEachSuppress(Consumer<? super T> consumer) {
  RuntimeException ex = null;
  int count = 0;
  for (T k : keys) {
    if (k != null) {
      try {
        consumer.accept(k);
      } catch (Throwable e) {
        if (ex == null) {
          ex = new RuntimeException("Multiple exceptions");
        }
        count++;
        ex.addSuppressed(e);
      }
    }
  }
  if (count == 1) {
    return ex.getSuppressed()[0];
  }
  return ex;
}

代码示例来源:origin: org.nuxeo.ecm.core/nuxeo-core-schema

if (errors.getSuppressed().length > 0) {
  throw errors;

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

@Override
public void abort()
{
  RuntimeException error = new RuntimeException("Exception during rollback");
  for (PageBuffer pageBuffer : pageWriter.getPageBuffers()) {
    try {
      pageBuffer.getStoragePageSink().rollback();
    }
    catch (Throwable t) {
      // Self-suppression not permitted
      if (error != t) {
        error.addSuppressed(t);
      }
    }
  }
  if (error.getSuppressed().length > 0) {
    throw error;
  }
}

代码示例来源:origin: com.facebook.presto/presto-raptor

@Override
public void abort()
{
  RuntimeException error = new RuntimeException("Exception during rollback");
  for (PageBuffer pageBuffer : pageWriter.getPageBuffers()) {
    try {
      pageBuffer.getStoragePageSink().rollback();
    }
    catch (Throwable t) {
      // Self-suppression not permitted
      if (error != t) {
        error.addSuppressed(t);
      }
    }
  }
  if (error.getSuppressed().length > 0) {
    throw error;
  }
}

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

@Test
public void testTryWithResourceApi_Never() throws Exception {
  try {
    try (Spy ignored = Sniffer.expectNever()) {
      executeStatement();
      throw new RuntimeException("This is a test exception");
    }
  } catch (RuntimeException e) {
    assertEquals("This is a test exception", e.getMessage());
    assertNotNull(e.getSuppressed());
    assertEquals(1, e.getSuppressed().length);
    assertTrue(WrongNumberOfQueriesError.class.isAssignableFrom(e.getSuppressed()[0].getClass()));
  }
}

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

@Test
public void testExecuteThrowsException() throws Exception {
  try {
    Sniffer.expect(1).execute(() -> {
      throw new RuntimeException();
    });
  } catch (RuntimeException e) {
    assertNotNull(e);
    assertNull(e.getCause());
    assertEquals(1, e.getSuppressed().length);
    assertTrue(WrongNumberOfQueriesError.class.isAssignableFrom(e.getSuppressed()[0].getClass()));
  }
}

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

@Test
public void testRunThrowsException() throws Exception {
  try {
    Sniffer.expect(1).run(() -> {
      throw new RuntimeException();
    });
  } catch (RuntimeException e) {
    assertNotNull(e);
    assertNull(e.getCause());
    assertEquals(1, e.getSuppressed().length);
    assertTrue(WrongNumberOfQueriesError.class.isAssignableFrom(e.getSuppressed()[0].getClass()));
  }
}

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

@Test
public void testCallThrowsException() throws Exception {
  try {
    Sniffer.expect(1).call(() -> {
      throw new RuntimeException();
    });
  } catch (RuntimeException e) {
    assertNotNull(e);
    assertNull(e.getCause());
    assertEquals(1, e.getSuppressed().length);
    assertTrue(WrongNumberOfQueriesError.class.isAssignableFrom(e.getSuppressed()[0].getClass()));
  }
}

代码示例来源:origin: uk.co.nichesolutions.presto/presto-main

if (closeError.getSuppressed().length > 0) {
  throw closeError;

代码示例来源:origin: io.prestosql/presto-main

if (closeError.getSuppressed().length > 0) {
  throw closeError;

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

if (closeError.getSuppressed().length > 0) {
  throw closeError;

代码示例来源:origin: vmware/xenon

} catch (RuntimeException e) {
  throw ExceptionTestUtils.throwAsUnchecked(e.getSuppressed()[0]);

代码示例来源:origin: com.vmware.xenon/xenon-common

} catch (RuntimeException e) {
  throw ExceptionTestUtils.throwAsUnchecked(e.getSuppressed()[0]);

相关文章