Package no.digipost
Class DiggExceptions
java.lang.Object
no.digipost.DiggExceptions
-
Field Summary
FieldsModifier and TypeFieldDescriptionThis consumer rethrows any givenExceptionas an uncheckedRuntimeException. -
Method Summary
Modifier and TypeMethodDescriptionstatic <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.static RuntimeExceptionUtility for acquiring aRuntimeExceptionfrom anyThrowable.static RuntimeExceptionasUnchecked(Throwable t, String message) Utility for acquiring aRuntimeExceptionwith a custom message from anyThrowable.static <X extends Throwable>
RuntimeExceptionasUnchecked(X t, Function<? super X, String> messageCreator) Utility for acquiring aRuntimeExceptionwith a custom message from anyThrowable.static StringGenerate a concise description of an exception/throwable containing the"friendly name"of the exception's type, and itsmessage.static <T> TgetUnchecked(ThrowingSupplier<T, ? extends Throwable> supplier) Immediatelygeta result from the givensupplier, and if needed, convert any thrown exceptions to unckecked.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.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.static final <T,X extends Throwable>
ThrowingConsumer<T,X> mayThrow(ThrowingConsumer<T, X> consumer) Convenience to acquire aThrowingConsumer-reference from a lambda expression.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.static final <T,X extends Throwable>
ThrowingRunnable<X>mayThrow(ThrowingRunnable<X> runnable) Convenience to acquire aThrowingRunnable-reference from a lambda expression.static final <T,X extends Throwable>
ThrowingSupplier<T,X> mayThrow(ThrowingSupplier<T, X> supplier) Convenience to acquire aThrowingSupplier-reference from a lambda expression.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 Details
-
rethrowAnyException
This consumer rethrows any givenExceptionas an uncheckedRuntimeException.
-
-
Method Details
-
causalChainOf
- Parameters:
t- the Throwable to get the causal chain from.- Returns:
- the entire chain of causes, including the given Throwable.
-
exceptionNameAndMessage
Generate a concise description of an exception/throwable containing the"friendly name"of the exception's type, and itsmessage.- Parameters:
t- the exception/throwable- Returns:
- the description
-
asUnchecked
Utility for acquiring aRuntimeExceptionfrom anyThrowable. This method is appropriate to use when you have caught an exception which you have no ability to handle, and you need to just throw it from a context where you are not allowed to.If you want to add more context to the thrown exception (which you probably should), consider using
asUnchecked(Throwable, String)orasUnchecked(Throwable, Function).- Parameters:
t- the exception (Throwable)- Returns:
- a new
RuntimeExceptionwhich has the given exception as itscause, ortitself casted toRuntimeExceptionif possible
-
asUnchecked
public static <X extends Throwable> RuntimeException asUnchecked(X t, Function<? super X, String> messageCreator) Utility for acquiring aRuntimeExceptionwith a custom message from anyThrowable. The result from this method will always be a new exception instance.- Type Parameters:
X- the type of the given exception- Parameters:
t- the exception (Throwable)messageCreator- a function which returns the message for the new exception- Returns:
- a new
RuntimeExceptionwhich has the result from themessageCreatorfunction as itsmessage, and the given exception as itscause
-
asUnchecked
Utility for acquiring aRuntimeExceptionwith a custom message from anyThrowable. The result from this method will always be a new exception instance.- Parameters:
t- the exception (Throwable)message- the message for the new exception- Returns:
- a new
RuntimeExceptionwhich has the givenmessage, and the given exception as itscause
-
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
Immediatelygeta result from the givensupplier, and if needed, convert any thrown exceptions to unckecked.- Parameters:
supplier- TheThrowingSupplier.- Returns:
- the result.
-
runUnchecked
Immediatelyrunthe givenrunnable, and if needed, convert any thrown exceptions to unckecked.- Parameters:
runnable- TheThrowingRunnable.
-
mayThrow
public static final <T,R, ThrowingFunction<T,X extends Throwable> R, mayThrowX> (ThrowingFunction<T, R, X> function) Convenience to acquire aThrowingFunction-reference from a lambda expression. -
mayThrow
public static final <T,U, ThrowingBiFunction<T,R, X extends Throwable> U, mayThrowR, X> (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, ThrowingBiConsumer<T,X extends Throwable> U, mayThrowX> (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.
-