Package cn.sliew.milky.common.exception
Class ThrowableCollector<T>
- java.lang.Object
-
- cn.sliew.milky.common.exception.ThrowableCollector<T>
-
public class ThrowableCollector<T> extends Object
Component that can collect one Throwable instance.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceThrowableCollector.ExecutableFunctional interface for an executable block of code that may throw aThrowable.static interfaceThrowableCollector.ExecutableWithResult<T>Functional interface for an executable block of code that may throw aThrowable.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static <T> ThrowableCollector<T>create()Factory method forThrowableCollectorinstances creation.voidexecute(ThrowableCollector.Executable executable)Execute the suppliedThrowableCollector.Executableand collect anyThrowablethrown during the execution.Optional<T>execute(ThrowableCollector.ExecutableWithResult<T> executable)Optional<Throwable>getThrowable()Get the firstThrowablecollected by thisThrowableCollector.
-
-
-
Method Detail
-
execute
public void execute(ThrowableCollector.Executable executable)
Execute the suppliedThrowableCollector.Executableand collect anyThrowablethrown during the execution.If the
Executablethrows an unrecoverable exception — for example, anOutOfMemoryError— this method will rethrow it.- Parameters:
executable- theExecutableto execute
-
execute
public Optional<T> execute(ThrowableCollector.ExecutableWithResult<T> executable)
-
getThrowable
public Optional<Throwable> getThrowable()
Get the firstThrowablecollected by thisThrowableCollector.If this collector is not empty, the first collected
Throwablewill be returned with any additionalThrowablessuppressed in the firstThrowable.- Returns:
- the first collected
Throwableornullif thisThrowableCollectoris empty
-
create
public static <T> ThrowableCollector<T> create()
Factory method forThrowableCollectorinstances creation.- Returns:
- throwable collector
-
-