本文整理了Java中java.lang.Exception.getSuppressed()
方法的一些代码示例,展示了Exception.getSuppressed()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Exception.getSuppressed()
方法的具体详情如下:
包路径:java.lang.Exception
类名称:Exception
方法名:getSuppressed
暂无
代码示例来源:origin: wildfly/wildfly
private static <T extends Throwable> T copyContents(final Exception source, final T throwable) {
throwable.setStackTrace(source.getStackTrace());
final Throwable[] suppressed = source.getSuppressed();
if (suppressed != null) for (final Throwable t : suppressed) {
throwable.addSuppressed(t);
}
return throwable;
}
}
代码示例来源:origin: neo4j/neo4j
@Override
public boolean matches( Object item )
{
Exception e = (Exception) item;
for ( Throwable suppressed : e.getSuppressed() )
{
if ( suppressed instanceof ResourceCloseFailureException )
{
if ( suppressed.getCause() instanceof ExceptionDuringClose )
{
return true;
}
}
}
return false;
}
} );
代码示例来源:origin: SonarSource/sonarqube
@Test
public void log_error_as_suppressed_when_task_failed_with_MessageException_and_ending_state_can_not_be_persisted_to_db() throws Exception {
CeTask ceTask = createCeTask(submitter);
when(queue.peek(anyString())).thenReturn(Optional.of(ceTask));
taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
MessageException ex = makeTaskProcessorFail(ceTask, MessageException.of("simulate MessageException thrown by TaskProcessor#process"));
RuntimeException runtimeException = new RuntimeException("Simulate queue#remove failing");
doThrow(runtimeException).when(queue).remove(ceTask, CeActivityDto.Status.FAILED, null, ex);
underTest.call();
List<String> logs = logTester.logs(LoggerLevel.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.getLogin());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.getLogin()));
List<LogAndArguments> logAndArguments = logTester.getLogs(LoggerLevel.ERROR);
assertThat(logAndArguments).hasSize(1);
assertThat(logAndArguments.get(0).getFormattedMsg()).isEqualTo("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
Object arg1 = logAndArguments.get(0).getArgs().get()[0];
assertThat(arg1).isSameAs(runtimeException);
assertThat(((Exception) arg1).getSuppressed()).containsOnly(ex);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testTrace2() throws Exception {
Hooks.onOperatorDebug();
try {
Mono.just(1)
.map(d -> {
throw new RuntimeException();
})
.filter(d -> true)
.doOnNext(d -> System.currentTimeMillis())
.map(d -> d)
.block();
}
catch(Exception e){
e.printStackTrace();
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
("HooksTraceTest.java:"));
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tMono.map ⇢ reactor.HooksTraceTest.testTrace2(HooksTraceTest.java:"));
return;
}
finally {
Hooks.resetOnOperatorDebug();
}
throw new IllegalStateException();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testTraceComposed() throws Exception {
Hooks.onOperatorDebug();
try {
Mono.just(1)
.flatMap(d -> Mono.error(new RuntimeException()))
.filter(d -> true)
.doOnNext(d -> System.currentTimeMillis())
.map(d -> d)
.block();
}
catch (Exception e) {
e.printStackTrace();
Assert.assertTrue(e.getSuppressed()[0].getMessage()
.contains("HooksTraceTest.java:"));
Assert.assertTrue(e.getSuppressed()[0].getMessage()
.contains("|_\tMono.flatMap ⇢ reactor.HooksTraceTest.testTraceComposed(HooksTraceTest.java:"));
return;
}
finally {
Hooks.resetOnOperatorDebug();
}
throw new IllegalStateException();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testTrace() throws Exception {
Hooks.onOperatorDebug();
try {
Mono.fromCallable(() -> {
throw new RuntimeException();
})
.map(d -> d)
.block();
}
catch(Exception e){
e.printStackTrace();
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("MonoCallable"));
return;
}
finally {
Hooks.resetOnOperatorDebug();
}
throw new IllegalStateException();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testTraceDefer() throws Exception {
Hooks.onOperatorDebug();
try {
Mono.defer(() -> Mono.just(1)
.flatMap(d -> Mono.error(new RuntimeException()))
.filter(d -> true)
.doOnNext(d -> System.currentTimeMillis())
.map(d -> d))
.block();
}
catch(Exception e){
e.printStackTrace();
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
("HooksTraceTest.java:"));
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tMono.flatMap ⇢ reactor.HooksTraceTest.lambda$testTraceDefer$14(HooksTraceTest.java:"));
return;
}
finally {
Hooks.resetOnOperatorDebug();
}
throw new IllegalStateException();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void log_error_when_task_failed_and_ending_state_can_not_be_persisted_to_db() throws Exception {
CeTask ceTask = createCeTask(submitter);
when(queue.peek(anyString())).thenReturn(Optional.of(ceTask));
taskProcessorRepository.setProcessorForTask(CeTaskTypes.REPORT, taskProcessor);
IllegalStateException ex = makeTaskProcessorFail(ceTask);
RuntimeException runtimeException = new RuntimeException("Simulate queue#remove failing");
doThrow(runtimeException).when(queue).remove(ceTask, CeActivityDto.Status.FAILED, null, ex);
underTest.call();
List<String> logs = logTester.logs(LoggerLevel.INFO);
assertThat(logs).hasSize(2);
assertThat(logs.get(0)).contains(" | submitter=" + submitter.getLogin());
assertThat(logs.get(1)).contains(String.format(" | submitter=%s | status=FAILED | time=", submitter.getLogin()));
List<LogAndArguments> logAndArguments = logTester.getLogs(LoggerLevel.ERROR);
assertThat(logAndArguments).hasSize(2);
LogAndArguments executionErrorLog = logAndArguments.get(0);
assertThat(executionErrorLog.getFormattedMsg()).isEqualTo("Failed to execute task " + ceTask.getUuid());
assertThat(executionErrorLog.getArgs().get()).containsOnly(ceTask.getUuid(), ex);
LogAndArguments finalizingErrorLog = logAndArguments.get(1);
assertThat(finalizingErrorLog.getFormattedMsg()).isEqualTo("Failed to finalize task with uuid '" + ceTask.getUuid() + "' and persist its state to db");
Object arg1 = finalizingErrorLog.getArgs().get()[0];
assertThat(arg1).isSameAs(runtimeException);
assertThat(((Exception) arg1).getSuppressed()).containsOnly(ex);
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testTrace3() throws Exception {
Hooks.onOperatorDebug();
try {
Flux.just(1)
.map(d -> {
throw new RuntimeException();
})
.share()
.filter(d -> true)
.doOnNext(d -> System.currentTimeMillis())
.map(d -> d)
.blockLast();
}
catch(Exception e){
e.printStackTrace();
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
("HooksTraceTest.java:"));
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains("|_\tFlux.share ⇢ reactor.HooksTraceTest.testTrace3(HooksTraceTest.java:"));
return;
}
finally {
Hooks.resetOnOperatorDebug();
}
throw new IllegalStateException();
}
代码示例来源:origin: reactor/reactor-core
@Test
public void testTraceComposed2() throws Exception {
Hooks.onOperatorDebug();
try {
Flux.just(1)
.flatMap(d -> {
throw new RuntimeException();
})
.filter(d -> true)
.doOnNext(d -> System.currentTimeMillis())
.map(d -> d)
.blockLast();
}
catch(Exception e){
e.printStackTrace();
Assert.assertTrue(e.getSuppressed()[0].getMessage().contains
("HooksTraceTest.java:"));
assertThat(e.getSuppressed()[0].getMessage()).contains("|_\tFlux.flatMap ⇢ reactor.HooksTraceTest.testTraceComposed2(HooksTraceTest.java:");
return;
}
finally {
Hooks.resetOnOperatorDebug();
}
throw new IllegalStateException();
}
代码示例来源:origin: real-logic/agrona
for (final Throwable suppressed : e.getSuppressed())
for (final Throwable suppressed : e.getSuppressed())
代码示例来源:origin: fabric8io/kubernetes-client
logger.error(e.getMessage(), e);
Throwable[] suppressed = e.getSuppressed();
if (suppressed != null) {
for (Throwable t : suppressed) {
代码示例来源:origin: fabric8io/kubernetes-client
public static void main(String[] args) throws InterruptedException {
String master = "https://localhost:8443/";
if (args.length == 1) {
master = args[0];
}
Config config = new ConfigBuilder().withMasterUrl(master)
.withTrustCerts(true)
.withUsername("admin")
.withPassword("admin")
.withNamespace("default")
.build();
try (final KubernetesClient client = new AutoAdaptableKubernetesClient(config)) {
log("Received pods", client.pods().list());
} catch (Exception e) {
e.printStackTrace();
logger.error(e.getMessage(), e);
Throwable[] suppressed = e.getSuppressed();
if (suppressed != null) {
for (Throwable t : suppressed) {
logger.error(t.getMessage(), t);
}
}
}
}
代码示例来源:origin: palatable/lambda
@Test
public void withResourcesPreservesSuppressedExceptionThrownDuringClose() {
RuntimeException rootException = new RuntimeException();
IOException nestedIOException = new IOException();
Try<Exception, Exception> failure = Try.withResources(() -> () -> { throw nestedIOException; },
resource -> { throw rootException; });
Exception thrown = failure.recover(id());
assertEquals(thrown, rootException);
assertArrayEquals(new Throwable[]{nestedIOException}, thrown.getSuppressed());
}
代码示例来源:origin: org.wildfly.security/wildfly-elytron-mechanism
private static <T extends Throwable> T copyContents(final Exception source, final T throwable) {
throwable.setStackTrace(source.getStackTrace());
final Throwable[] suppressed = source.getSuppressed();
if (suppressed != null) for (final Throwable t : suppressed) {
throwable.addSuppressed(t);
}
return throwable;
}
}
代码示例来源:origin: org.wildfly.security/wildfly-elytron
private static <T extends Throwable> T copyContents(final Exception source, final T throwable) {
throwable.setStackTrace(source.getStackTrace());
final Throwable[] suppressed = source.getSuppressed();
if (suppressed != null) for (final Throwable t : suppressed) {
throwable.addSuppressed(t);
}
return throwable;
}
}
代码示例来源:origin: au.net.zeus.jgdms/jgdms-platform
private void writeObject(ObjectOutputStream out) throws IOException {
ObjectOutputStream.PutField pf = out.putFields();
pf.put("message", super.getMessage());
Throwable cause = super.getCause();
if (cause == this) cause = null;
pf.put("cause", cause);
pf.put("stack", super.getStackTrace());
pf.put("suppressed", super.getSuppressed());
out.writeFields();
}
代码示例来源:origin: org.apache.beam/beam-runners-direct-java
@Override
public boolean matches(Object item) {
if (!(item instanceof Exception)) {
return false;
}
Exception that = (Exception) item;
return Matchers.containsInAnyOrder(suppressions)
.matches(ImmutableList.copyOf(that.getSuppressed()));
}
});
代码示例来源:origin: seznam/euphoria
@Test
public void testSuppressedIOException() throws IOException {
try {
IOUtils.forEach(Arrays.asList(1, 2, 3), (i) -> {
throw new IOException("Number: " + i);
});
} catch (Exception e) {
assertEquals(2, e.getSuppressed().length); //two supressed exceptions and one thrown
assertTrue(e instanceof IOException);
assertEquals("Number: 1", e.getMessage());
}
}
代码示例来源:origin: fabric8io/kubernetes-client
Throwable[] suppressed = e.getSuppressed();
if (suppressed != null) {
for (Throwable t : suppressed) {
内容来源于网络,如有侵权,请联系作者删除!