Package com.optum.sourcehawk.core.utils
Class Try
- java.lang.Object
-
- com.optum.sourcehawk.core.utils.Try
-
public final class Try extends Object
Utility class for try/catch handling- Author:
- Brian Wyka
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTry.CheckedSupplier<T>A checked supplier functional interface
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> TattemptOrDefault(Try.CheckedSupplier<T> supplier, Function<Throwable,T> defaultFunction)Surround theTry.CheckedSupplierwith a try/catch
-
-
-
Method Detail
-
attemptOrDefault
public static <T> T attemptOrDefault(Try.CheckedSupplier<T> supplier, Function<Throwable,T> defaultFunction)
Surround theTry.CheckedSupplierwith a try/catch- Type Parameters:
T- the type of the return value- Parameters:
supplier- the supplier of the return valuedefaultFunction- the default value function if an exception is thrown- Returns:
- the result of the supplier if successful, otherwise the result of the default function
-
-