java.sql.SQLException.getSuppressed()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(2.0k)|赞(0)|评价(0)|浏览(136)

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

SQLException.getSuppressed介绍

暂无

代码示例

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

private void assertSuppressions(Throwable cause) {
    LoggerFactory.getLogger(TestBatchExceptionRewrite.class).info("exception", cause);
    SQLException e = (SQLException) cause;
    SQLException nextException = e.getNextException();
    assertThat((Exception) nextException).isEqualTo(e.getSuppressed()[0]);
    assertThat((Exception) nextException.getNextException()).isNull();
    assertThat(e.getSuppressed()).hasSize(1);
  }
}

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

@Test
public void testEventuallyFails() {
  final AtomicInteger attempts = new AtomicInteger(0);
  Handle handle = dbRule.getJdbi().open();
  assertThatExceptionOfType(SQLException.class)
    .isThrownBy(() -> handle.inTransaction(TransactionIsolationLevel.SERIALIZABLE,
      conn -> {
        attempts.incrementAndGet();
        throw new SQLException("serialization", "40001", attempts.get());
      }))
    .satisfies(e -> assertThat(e.getSQLState()).isEqualTo("40001"))
    .satisfies(e -> assertThat(e.getSuppressed())
      .hasSize(MAX_RETRIES)
      .describedAs("suppressed are ordered reverse chronologically, like a stack")
      .isSortedAccordingTo(Comparator.comparing(ex -> ((SQLException) ex).getErrorCode()).reversed()))
    .describedAs("thrown exception is chronologically last")
    .satisfies(e -> assertThat(e.getErrorCode()).isEqualTo(((SQLException) e.getSuppressed()[0]).getErrorCode() + 1));
  assertThat(attempts.get()).isEqualTo(1 + MAX_RETRIES);
}

代码示例来源:origin: jbosstm/narayana

.getNextException();
Throwable[] suppressed = e.getSuppressed();
for (int j = 0; j < suppressed.length; j++) {
  suppressed[j].printStackTrace();

代码示例来源:origin: jbosstm/narayana

.getNextException();
Throwable[] suppressed = e.getSuppressed();
for (int j = 0; j < suppressed.length; j++) {
  suppressed[j].printStackTrace();

相关文章