Class ThrowableSuppressor
- java.lang.Object
-
- org.jdbi.v3.core.internal.exceptions.ThrowableSuppressor
-
public final class ThrowableSuppressor extends java.lang.ObjectManage multi-exception chains by adding additional throwables as suppressed.
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.LinkedList<java.lang.Throwable>throwables
-
Constructor Summary
Constructors Constructor Description ThrowableSuppressor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidattachToThrowable(java.lang.Throwable throwable)Attach all recorded exceptions to another throwable as suppressed exceptions.<T> TsuppressAppend(CheckedSupplier<T> supplier, T defaultValue)Run a piece of code and record any thrown exception at the end of the exception chain.voidsuppressAppend(Unchecked.CheckedRunnable runnable)Run a piece of code and record any thrown exception at the end of the exception chain.<T> TsuppressPrepend(CheckedSupplier<T> supplier, T defaultValue)Run a piece of code and record any thrown exception at the beginning of the exception chain.voidsuppressPrepend(Unchecked.CheckedRunnable runnable)Run a piece of code and record any thrown exception at the beginning of the exception chain.voidthrowIfNecessary()If any throwables were recorded, use the first as the primary exception and attach all other suppressed exceptions to it.<T extends java.lang.Throwable>
voidthrowIfNecessary(java.util.function.Function<java.lang.Throwable,T> function)Attach all recorded exceptions to a new throwable and throw it.
-
-
-
Method Detail
-
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(java.lang.Throwable throwable)
Attach all recorded exceptions to another throwable as suppressed exceptions.- Parameters:
throwable- The throwable to attach to.
-
throwIfNecessary
public <T extends java.lang.Throwable> void throwIfNecessary(java.util.function.Function<java.lang.Throwable,T> function) throws T extends java.lang.ThrowableAttach 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 java.lang.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.
-
-