private void suppress(Throwable thrown, Throwable suppressed) { if (thrown != suppressed) { thrown.addSuppressed(suppressed); } } }
public static <T extends Throwable> T chain( T initial, T current ) { if ( initial == null ) { return current; } if ( current != null ) { initial.addSuppressed( current ); } return initial; }
@SuppressWarnings("ObjectEquality") private static void closeWithSuppression(Connection connection, Throwable throwable) { try { connection.close(); } catch (Throwable t) { // Self-suppression not permitted if (throwable != t) { throwable.addSuppressed(t); } } } }
private void handleException(Throwable ex) { if (backgroundExceptionHandler != null) { try { backgroundExceptionHandler.uncaughtException(null, ex); } catch(Throwable ignore) { if (ex != ignore) { // OOME may be the same ex.addSuppressed(ignore); } } } }
/** * @deprecated Use {@link Throwable#addSuppressed(Throwable)} instead. */ @Deprecated public static <T extends Throwable> T withSuppressed( T exception, Throwable... suppressed ) { if ( suppressed != null ) { for ( Throwable s : suppressed ) { exception.addSuppressed( s ); } } return exception; }
private void closeWithSuppression(Throwable throwable) { requireNonNull(throwable, "throwable is null"); try { close(); } catch (Exception e) { if (e != throwable) { throwable.addSuppressed(e); } } }
protected void closeWithSuppression(Throwable throwable) { requireNonNull(throwable, "throwable is null"); try { close(); } catch (RuntimeException e) { // Self-suppression not permitted if (throwable != e) { throwable.addSuppressed(e); } } }
private void closeWithSuppression(Throwable throwable) { requireNonNull(throwable, "throwable is null"); try { close(); } catch (RuntimeException e) { // Self-suppression not permitted if (e != throwable) { throwable.addSuppressed(e); } } }
protected void closeWithSuppression(Throwable throwable) { requireNonNull(throwable, "throwable is null"); try { close(); } catch (RuntimeException e) { // Self-suppression not permitted if (throwable != e) { throwable.addSuppressed(e); } } }
public static void closeWithSuppression(RecordCursor recordCursor, Throwable throwable) { requireNonNull(recordCursor, "recordCursor is null"); requireNonNull(throwable, "throwable is null"); try { recordCursor.close(); } catch (RuntimeException e) { // Self-suppression not permitted if (throwable != e) { throwable.addSuppressed(e); } } }
@SuppressJava6Requirement(reason = "Throwable addSuppressed is only available for >= 7. Has check for < 7.") public static void addSuppressed(Throwable target, Throwable suppressed) { if (!haveSuppressed()) { return; } target.addSuppressed(suppressed); }
@SuppressJava6Requirement(reason = "Throwable addSuppressed is only available for >= 7. Has check for < 7.") public static void addSuppressed(Throwable target, Throwable suppressed) { if (!haveSuppressed()) { return; } target.addSuppressed(suppressed); }
private <EX extends Throwable> EX withCallTraces( EX failure ) { for ( StackTraceElement[] waitCall : waitCalls ) { RuntimeException call = new RuntimeException( "Wait called" ); call.setStackTrace( waitCall ); failure.addSuppressed( call ); } return failure; } }
public void assertInvalidFunction(String projection, SemanticErrorCode expectedErrorCode) { try { evaluateInvalid(projection); fail(format("Expected to throw %s exception", expectedErrorCode)); } catch (SemanticException e) { try { assertEquals(e.getCode(), expectedErrorCode); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
public void assertInvalidCast(String projection) { try { evaluateInvalid(projection); fail("Expected to throw an INVALID_CAST_ARGUMENT exception"); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), INVALID_CAST_ARGUMENT.toErrorCode()); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
public void assertInvalidFunction(String projection, ErrorCodeSupplier expectedErrorCode) { try { evaluateInvalid(projection); fail(format("Expected to throw %s exception", expectedErrorCode.toErrorCode())); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), expectedErrorCode.toErrorCode()); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
public void assertNumericOverflow(String projection, String message) { try { evaluateInvalid(projection); fail("Expected to throw an NUMERIC_VALUE_OUT_OF_RANGE exception with message " + message); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), NUMERIC_VALUE_OUT_OF_RANGE.toErrorCode()); assertEquals(e.getMessage(), message); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
protected void assertNotSupported(String projection, String message) { try { functionAssertions.executeProjectionWithFullEngine(projection); fail("expected exception"); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), NOT_SUPPORTED.toErrorCode()); assertEquals(e.getMessage(), message); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
public void assertInvalidCast(String projection, String message) { try { evaluateInvalid(projection); fail("Expected to throw an INVALID_CAST_ARGUMENT exception"); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), INVALID_CAST_ARGUMENT.toErrorCode()); assertEquals(e.getMessage(), message); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }
public void assertInvalidFunction(String projection, StandardErrorCode errorCode, String messagePattern) { try { evaluateInvalid(projection); fail("Expected to throw a PrestoException with message matching " + messagePattern); } catch (PrestoException e) { try { assertEquals(e.getErrorCode(), errorCode.toErrorCode()); assertTrue(e.getMessage().equals(messagePattern) || e.getMessage().matches(messagePattern), format("Error message [%s] doesn't match [%s]", e.getMessage(), messagePattern)); } catch (Throwable failure) { failure.addSuppressed(e); throw failure; } } }