Package no.digipost
Class DiggExceptions
- java.lang.Object
-
- no.digipost.DiggExceptions
-
public final class DiggExceptions extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static Consumer<Exception>rethrowAnyExceptionThis consumer rethrows any givenExceptionas an uncheckedRuntimeException.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,R>
RapplyUnchecked(ThrowingFunction<T,R,? extends Throwable> function, T argument)Immediatelyapplythe givenfunctionwith the givenargument, and if needed, convert any thrown exceptions to unckecked.static RuntimeExceptionasUnchecked(Throwable t)static <X extends Throwable>
RuntimeExceptionasUnchecked(X t, Function<? super X,String> message)static Stream<Throwable>causalChainOf(Throwable t)static StringexceptionNameAndMessage(Throwable t)static <T> TgetUnchecked(ThrowingSupplier<T,? extends Throwable> supplier)Immediatelygeta result from the givensupplier, and if needed, convert any thrown exceptions to unckecked.static <T,U,X extends Throwable>
ThrowingBiConsumer<T,U,X>mayThrow(ThrowingBiConsumer<T,U,X> consumer)Convenience to acquire aThrowingBiConsumer-reference from a lambda expression.static <T,U,R,X extends Throwable>
ThrowingBiFunction<T,U,R,X>mayThrow(ThrowingBiFunction<T,U,R,X> bifunction)Convenience to acquire aThrowingBiFunction-reference from a lambda expression.static <T,X extends Throwable>
ThrowingConsumer<T,X>mayThrow(ThrowingConsumer<T,X> consumer)Convenience to acquire aThrowingConsumer-reference from a lambda expression.static <T,R,X extends Throwable>
ThrowingFunction<T,R,X>mayThrow(ThrowingFunction<T,R,X> function)Convenience to acquire aThrowingFunction-reference from a lambda expression.static <T,X extends Throwable>
ThrowingRunnable<X>mayThrow(ThrowingRunnable<X> runnable)Convenience to acquire aThrowingRunnable-reference from a lambda expression.static <T,X extends Throwable>
ThrowingSupplier<T,X>mayThrow(ThrowingSupplier<T,X> supplier)Convenience to acquire aThrowingSupplier-reference from a lambda expression.static <T extends Throwable>
Consumer<T>rethrow(Function<T,? extends RuntimeException> createUnchecked)Create a exception handler (Consumer) which simply rethrows given exceptions.static voidrunUnchecked(ThrowingRunnable<? extends Throwable> runnable)Immediatelyrunthe givenrunnable, and if needed, convert any thrown exceptions to unckecked.
-
-
-
Field Detail
-
rethrowAnyException
public static final Consumer<Exception> rethrowAnyException
This consumer rethrows any givenExceptionas an uncheckedRuntimeException.
-
-
Method Detail
-
causalChainOf
public static Stream<Throwable> causalChainOf(Throwable t)
- Parameters:
t- the Throwable to get the causal chain from.- Returns:
- the entire chain of causes, including the given Throwable.
-
asUnchecked
public static RuntimeException asUnchecked(Throwable t)
-
asUnchecked
public static <X extends Throwable> RuntimeException asUnchecked(X t, Function<? super X,String> message)
-
applyUnchecked
public static <T,R> R applyUnchecked(ThrowingFunction<T,R,? extends Throwable> function, T argument)
Immediatelyapplythe givenfunctionwith the givenargument, and if needed, convert any thrown exceptions to unckecked.- Parameters:
function- TheThrowingFunction.argument- The argument to pass toThrowingFunction.apply(Object)- Returns:
- the result.
-
getUnchecked
public static <T> T getUnchecked(ThrowingSupplier<T,? extends Throwable> supplier)
Immediatelygeta result from the givensupplier, and if needed, convert any thrown exceptions to unckecked.- Parameters:
supplier- TheThrowingSupplier.- Returns:
- the result.
-
runUnchecked
public static void runUnchecked(ThrowingRunnable<? extends Throwable> runnable)
Immediatelyrunthe givenrunnable, and if needed, convert any thrown exceptions to unckecked.- Parameters:
runnable- TheThrowingRunnable.
-
mayThrow
public static final <T,R,X extends Throwable> ThrowingFunction<T,R,X> mayThrow(ThrowingFunction<T,R,X> function)
Convenience to acquire aThrowingFunction-reference from a lambda expression.
-
mayThrow
public static final <T,U,R,X extends Throwable> ThrowingBiFunction<T,U,R,X> mayThrow(ThrowingBiFunction<T,U,R,X> bifunction)
Convenience to acquire aThrowingBiFunction-reference from a lambda expression.
-
mayThrow
public static final <T,X extends Throwable> ThrowingSupplier<T,X> mayThrow(ThrowingSupplier<T,X> supplier)
Convenience to acquire aThrowingSupplier-reference from a lambda expression.
-
mayThrow
public static final <T,X extends Throwable> ThrowingConsumer<T,X> mayThrow(ThrowingConsumer<T,X> consumer)
Convenience to acquire aThrowingConsumer-reference from a lambda expression.
-
mayThrow
public static final <T,U,X extends Throwable> ThrowingBiConsumer<T,U,X> mayThrow(ThrowingBiConsumer<T,U,X> consumer)
Convenience to acquire aThrowingBiConsumer-reference from a lambda expression.
-
mayThrow
public static final <T,X extends Throwable> ThrowingRunnable<X> mayThrow(ThrowingRunnable<X> runnable)
Convenience to acquire aThrowingRunnable-reference from a lambda expression.
-
rethrow
public static final <T extends Throwable> Consumer<T> rethrow(Function<T,? extends RuntimeException> createUnchecked)
Create a exception handler (Consumer) which simply rethrows given exceptions.- Parameters:
createUnchecked- a function to convert a (typically) checked exception toRuntimeException.- Returns:
- the
Consumerwhich rethrows any given exception.
-
-