Class ThrowableSuppressor

java.lang.Object
org.jdbi.v3.core.internal.exceptions.ThrowableSuppressor

public final class ThrowableSuppressor extends Object
Manage multi-exception chains by adding additional throwables as suppressed.
  • Field Details

  • Constructor Details

    • ThrowableSuppressor

      public ThrowableSuppressor()
  • Method Details

    • suppressAppend

      public <T> T suppressAppend(CheckedSupplier<T> supplier, T defaultValue)
      Run a piece of code and record any thrown exception at the end of the exception chain.
      Type Parameters:
      T - The return value type.
      Parameters:
      supplier - Code to execute.
      defaultValue - Default value if the code throws an exception.
      Returns:
      The output of the executed code or the default value in case of an exception.
    • suppressAppend

      public void suppressAppend(Unchecked.CheckedRunnable runnable)
      Run a piece of code and record any thrown exception at the end of the exception chain.
      Parameters:
      runnable - Code to execute.
    • suppressPrepend

      public <T> T suppressPrepend(CheckedSupplier<T> supplier, T defaultValue)
      Run a piece of code and record any thrown exception at the beginning of the exception chain.
      Type Parameters:
      T - The return value type.
      Parameters:
      supplier - Code to execute.
      defaultValue - Default value if the code throws an exception.
      Returns:
      The output of the executed code or the default value in case of an exception.
    • suppressPrepend

      public void suppressPrepend(Unchecked.CheckedRunnable runnable)
      Run a piece of code and record any thrown exception at the beginning of the exception chain.
      Parameters:
      runnable - Code to execute.
    • attachToThrowable

      public void attachToThrowable(Throwable throwable)
      Attach all recorded exceptions to another throwable as suppressed exceptions.
      Parameters:
      throwable - The throwable to attach to.
    • throwIfNecessary

      public <T extends Throwable> void throwIfNecessary(Function<Throwable,T> function) throws T
      Attach all recorded exceptions to a new throwable and throw it.
      Parameters:
      function - Returns the throwable to attach to. Only called if there are any additional throwables present. The first one present is passed into the function and is intended as the cause for the exception chain.
      Throws:
      T extends Throwable
    • throwIfNecessary

      public void throwIfNecessary()
      If any throwables were recorded, use the first as the primary exception and attach all other suppressed exceptions to it.