Class ThrowableSuppressor
java.lang.Object
org.jdbi.v3.core.internal.exceptions.ThrowableSuppressor
Manage multi-exception chains by adding additional throwables as suppressed.
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidattachToThrowable(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.voidIf any throwables were recorded, use the first as the primary exception and attach all other suppressed exceptions to it.<T extends Throwable>
voidthrowIfNecessary(Function<Throwable, T> function) Attach all recorded exceptions to a new throwable and throw it.
-
Field Details
-
throwables
-
-
Constructor Details
-
ThrowableSuppressor
public ThrowableSuppressor()
-
-
Method Details
-
suppressAppend
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
Run a piece of code and record any thrown exception at the end of the exception chain.- Parameters:
runnable- Code to execute.
-
suppressPrepend
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
Run a piece of code and record any thrown exception at the beginning of the exception chain.- Parameters:
runnable- Code to execute.
-
attachToThrowable
Attach all recorded exceptions to another throwable as suppressed exceptions.- Parameters:
throwable- The throwable to attach to.
-
throwIfNecessary
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.
-