Checked exceptions are one of Java's biggest flaws. Due to backwards-compatibility, we're inheriting all the checked exception trouble back from JDK 1.0. This becomes even more obvious when using lambda expressions, most of which are not allowed to throw checked exceptions.
This library tries to ease some pain and wraps / unwraps a variety of API elements from the JDK 8 to improve interoperability with checked exceptions.
- Author:
- Lukas Eder
-
Field Summary
FieldsModifier and TypeFieldDescriptionAConsumerthat rethrows all exceptions, including checked exceptions. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T,U> BiConsumer<T, U> biConsumer(CheckedBiConsumer<T, U> consumer) Wrap aCheckedBiConsumerin aBiConsumer.static <T,U> BiConsumer<T, U> biConsumer(CheckedBiConsumer<T, U> consumer, Consumer<Throwable> handler) Wrap aCheckedBiConsumerin aBiConsumerwith a custom handler for checked exceptions.static <T,U, R> BiFunction<T, U, R> biFunction(CheckedBiFunction<T, U, R> function) Wrap aCheckedBiFunctionin aBiFunction.static <T,U, R> BiFunction<T, U, R> biFunction(CheckedBiFunction<T, U, R> function, Consumer<Throwable> handler) Wrap aCheckedBiFunctionin aBiFunctionwith a custom handler for checked exceptions.static <T> BinaryOperator<T>binaryOperator(CheckedBinaryOperator<T> operator) Wrap aCheckedBinaryOperatorin aBinaryOperator.static <T> BinaryOperator<T>binaryOperator(CheckedBinaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedBinaryOperatorin aBinaryOperatorwith a custom handler for checked exceptions.static <T,U> BiPredicate<T, U> biPredicate(CheckedBiPredicate<T, U> predicate) Wrap aCheckedBiPredicatein aBiPredicate.static <T,U> BiPredicate<T, U> biPredicate(CheckedBiPredicate<T, U> predicate, Consumer<Throwable> handler) Wrap aCheckedBiPredicatein aBiPredicatewith a custom handler for checked exceptions.static BooleanSupplierbooleanSupplier(CheckedBooleanSupplier supplier) Wrap aCheckedBooleanSupplierin aBooleanSupplier.static BooleanSupplierbooleanSupplier(CheckedBooleanSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedBooleanSupplierin aBooleanSupplierwith a custom handler for checked exceptions.static <T> Callable<T>callable(CheckedCallable<T> callable) Wrap aCheckedCallable<T>in aCallable<T>.static <T> Callable<T>callable(CheckedCallable<T> callable, Consumer<Throwable> handler) Wrap aCheckedCallable<T>in aCallable<T>with a custom handler for checked exceptions.static <T> Comparator<T>comparator(CheckedComparator<T> comparator) Wrap aCheckedComparatorin aComparator.static <T> Comparator<T>comparator(CheckedComparator<T> comparator, Consumer<Throwable> handler) Wrap aCheckedComparatorin aComparatorwith a custom handler for checked exceptions.static <T> Consumer<T>consumer(CheckedConsumer<T> consumer) Wrap aCheckedConsumerin aConsumer.static <T> Consumer<T>consumer(CheckedConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedConsumerin aConsumerwith a custom handler for checked exceptions.static DoubleBinaryOperatorWrap aCheckedDoubleBinaryOperatorin aDoubleBinaryOperator.static DoubleBinaryOperatordoubleBinaryOperator(CheckedDoubleBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleBinaryOperatorin aDoubleBinaryOperatorwith a custom handler for checked exceptions.static DoubleConsumerdoubleConsumer(CheckedDoubleConsumer consumer) Wrap aCheckedDoubleConsumerin aDoubleConsumer.static DoubleConsumerdoubleConsumer(CheckedDoubleConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedDoubleConsumerin aDoubleConsumerwith a custom handler for checked exceptions.static <R> DoubleFunction<R>doubleFunction(CheckedDoubleFunction<R> function) Wrap aCheckedDoubleFunctionin aDoubleFunction.static <R> DoubleFunction<R>doubleFunction(CheckedDoubleFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedDoubleFunctionin aDoubleFunctionwith a custom handler for checked exceptions.static DoublePredicatedoublePredicate(CheckedDoublePredicate predicate) Wrap aCheckedDoublePredicatein aDoublePredicate.static DoublePredicatedoublePredicate(CheckedDoublePredicate function, Consumer<Throwable> handler) Wrap aCheckedDoublePredicatein aDoublePredicatewith a custom handler for checked exceptions.static DoubleSupplierdoubleSupplier(CheckedDoubleSupplier supplier) Wrap aCheckedDoubleSupplierin aDoubleSupplier.static DoubleSupplierdoubleSupplier(CheckedDoubleSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedDoubleSupplierin aDoubleSupplierwith a custom handler for checked exceptions.static DoubleToIntFunctionWrap aCheckedDoubleToIntFunctionin aDoubleToIntFunction.static DoubleToIntFunctiondoubleToIntFunction(CheckedDoubleToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToIntFunctionin aDoubleToIntFunctionwith a custom handler for checked exceptions.static DoubleToLongFunctionWrap aCheckedDoubleToLongFunctionin aDoubleToLongFunction.static DoubleToLongFunctiondoubleToLongFunction(CheckedDoubleToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToLongFunctionin aDoubleToLongFunctionwith a custom handler for checked exceptions.static DoubleUnaryOperatorWrap aCheckedDoubleUnaryOperatorin aDoubleUnaryOperator.static DoubleUnaryOperatordoubleUnaryOperator(CheckedDoubleUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleUnaryOperatorin aDoubleUnaryOperatorwith a custom handler for checked exceptions.static <T,R> Function<T, R> function(CheckedFunction<T, R> function) Wrap aCheckedFunctionin aFunction.static <T,R> Function<T, R> function(CheckedFunction<T, R> function, Consumer<Throwable> handler) Wrap aCheckedFunctionin aFunctionwith a custom handler for checked exceptions.static IntBinaryOperatorintBinaryOperator(CheckedIntBinaryOperator operator) Wrap aCheckedIntBinaryOperatorin aIntBinaryOperator.static IntBinaryOperatorintBinaryOperator(CheckedIntBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntBinaryOperatorin aIntBinaryOperatorwith a custom handler for checked exceptions.static IntConsumerintConsumer(CheckedIntConsumer consumer) Wrap aCheckedIntConsumerin aIntConsumer.static IntConsumerintConsumer(CheckedIntConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedIntConsumerin aIntConsumerwith a custom handler for checked exceptions.static <R> IntFunction<R>intFunction(CheckedIntFunction<R> function) Wrap aCheckedIntFunctionin aIntFunction.static <R> IntFunction<R>intFunction(CheckedIntFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedIntFunctionin aIntFunctionwith a custom handler for checked exceptions.static IntPredicateintPredicate(CheckedIntPredicate predicate) Wrap aCheckedPredicatein aIntPredicate.static IntPredicateintPredicate(CheckedIntPredicate function, Consumer<Throwable> handler) Wrap aCheckedPredicatein aIntPredicatewith a custom handler for checked exceptions.static IntSupplierintSupplier(CheckedIntSupplier supplier) Wrap aCheckedIntSupplierin aIntSupplier.static IntSupplierintSupplier(CheckedIntSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedIntSupplierin aIntSupplierwith a custom handler for checked exceptions.static IntToDoubleFunctionWrap aCheckedIntToDoubleFunctionin aIntToDoubleFunction.static IntToDoubleFunctionintToDoubleFunction(CheckedIntToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToDoubleFunctionin aIntToDoubleFunctionwith a custom handler for checked exceptions.static IntToLongFunctionintToLongFunction(CheckedIntToLongFunction function) Wrap aCheckedIntToLongFunctionin aIntToLongFunction.static IntToLongFunctionintToLongFunction(CheckedIntToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToLongFunctionin aIntToLongFunctionwith a custom handler for checked exceptions.static IntUnaryOperatorintUnaryOperator(CheckedIntUnaryOperator operator) Wrap aCheckedIntUnaryOperatorin aIntUnaryOperator.static IntUnaryOperatorintUnaryOperator(CheckedIntUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntUnaryOperatorin aIntUnaryOperatorwith a custom handler for checked exceptions.static LongBinaryOperatorlongBinaryOperator(CheckedLongBinaryOperator operator) Wrap aCheckedLongBinaryOperatorin aLongBinaryOperator.static LongBinaryOperatorlongBinaryOperator(CheckedLongBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongBinaryOperatorin aLongBinaryOperatorwith a custom handler for checked exceptions.static LongConsumerlongConsumer(CheckedLongConsumer consumer) Wrap aCheckedLongConsumerin aLongConsumer.static LongConsumerlongConsumer(CheckedLongConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedLongConsumerin aLongConsumerwith a custom handler for checked exceptions.static <R> LongFunction<R>longFunction(CheckedLongFunction<R> function) Wrap aCheckedLongFunctionin aLongFunction.static <R> LongFunction<R>longFunction(CheckedLongFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedLongFunctionin aLongFunctionwith a custom handler for checked exceptions.static LongPredicatelongPredicate(CheckedLongPredicate predicate) Wrap aCheckedLongPredicatein aLongPredicate.static LongPredicatelongPredicate(CheckedLongPredicate function, Consumer<Throwable> handler) Wrap aCheckedLongPredicatein aLongPredicatewith a custom handler for checked exceptions.static LongSupplierlongSupplier(CheckedLongSupplier supplier) Wrap aCheckedLongSupplierin aLongSupplier.static LongSupplierlongSupplier(CheckedLongSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedLongSupplierin aLongSupplierwith a custom handler for checked exceptions.static LongToDoubleFunctionWrap aCheckedLongToDoubleFunctionin aLongToDoubleFunction.static LongToDoubleFunctionlongToDoubleFunction(CheckedLongToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToDoubleFunctionin aLongToDoubleFunctionwith a custom handler for checked exceptions.static LongToIntFunctionlongToIntFunction(CheckedLongToIntFunction function) Wrap aCheckedLongToIntFunctionin aLongToIntFunction.static LongToIntFunctionlongToIntFunction(CheckedLongToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToIntFunctionin aLongToIntFunctionwith a custom handler for checked exceptions.static LongUnaryOperatorlongUnaryOperator(CheckedLongUnaryOperator operator) Wrap aCheckedLongUnaryOperatorin aLongUnaryOperator.static LongUnaryOperatorlongUnaryOperator(CheckedLongUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongUnaryOperatorin aLongUnaryOperatorwith a custom handler for checked exceptions.static <T> ObjDoubleConsumer<T>objDoubleConsumer(CheckedObjDoubleConsumer<T> consumer) Wrap aCheckedObjDoubleConsumerin aObjDoubleConsumer.static <T> ObjDoubleConsumer<T>objDoubleConsumer(CheckedObjDoubleConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjDoubleConsumerin aObjDoubleConsumerwith a custom handler for checked exceptions.static <T> ObjIntConsumer<T>objIntConsumer(CheckedObjIntConsumer<T> consumer) Wrap aCheckedObjIntConsumerin aObjIntConsumer.static <T> ObjIntConsumer<T>objIntConsumer(CheckedObjIntConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjIntConsumerin aObjIntConsumerwith a custom handler for checked exceptions.static <T> ObjLongConsumer<T>objLongConsumer(CheckedObjLongConsumer<T> consumer) Wrap aCheckedObjLongConsumerin aObjLongConsumer.static <T> ObjLongConsumer<T>objLongConsumer(CheckedObjLongConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjLongConsumerin aObjLongConsumerwith a custom handler for checked exceptions.static <T> Predicate<T>predicate(CheckedPredicate<T> predicate) Wrap aCheckedPredicatein aPredicate.static <T> Predicate<T>predicate(CheckedPredicate<T> function, Consumer<Throwable> handler) Wrap aCheckedPredicatein aPredicatewith a custom handler for checked exceptions.static Runnablerunnable(CheckedRunnable runnable) Wrap aCheckedRunnablein aRunnable.static Runnablerunnable(CheckedRunnable runnable, Consumer<Throwable> handler) Wrap aCheckedRunnablein aRunnablewith a custom handler for checked exceptions.static <T> Supplier<T>supplier(CheckedSupplier<T> supplier) Wrap aCheckedSupplierin aSupplier.static <T> Supplier<T>supplier(CheckedSupplier<T> supplier, Consumer<Throwable> handler) Wrap aCheckedSupplierin aSupplierwith a custom handler for checked exceptions.static void"sneaky-throw" a checked exception or throwable.static <T,U> ToDoubleBiFunction<T, U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function) Wrap aCheckedToDoubleBiFunctionin aToDoubleBiFunction.static <T,U> ToDoubleBiFunction<T, U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleBiFunctionin aToDoubleBiFunctionwith a custom handler for checked exceptions.static <T> ToDoubleFunction<T>toDoubleFunction(CheckedToDoubleFunction<T> function) Wrap aCheckedToDoubleFunctionin aToDoubleFunction.static <T> ToDoubleFunction<T>toDoubleFunction(CheckedToDoubleFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleFunctionin aToDoubleFunctionwith a custom handler for checked exceptions.static <T,U> ToIntBiFunction<T, U> toIntBiFunction(CheckedToIntBiFunction<T, U> function) Wrap aCheckedToIntBiFunctionin aToIntBiFunction.static <T,U> ToIntBiFunction<T, U> toIntBiFunction(CheckedToIntBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToIntBiFunctionin aToIntBiFunctionwith a custom handler for checked exceptions.static <T> ToIntFunction<T>toIntFunction(CheckedToIntFunction<T> function) Wrap aCheckedToIntFunctionin aToIntFunction.static <T> ToIntFunction<T>toIntFunction(CheckedToIntFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToIntFunctionin aToIntFunctionwith a custom handler for checked exceptions.static <T,U> ToLongBiFunction<T, U> toLongBiFunction(CheckedToLongBiFunction<T, U> function) Wrap aCheckedToLongBiFunctionin aToLongBiFunction.static <T,U> ToLongBiFunction<T, U> toLongBiFunction(CheckedToLongBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToLongBiFunctionin aToLongBiFunctionwith a custom handler for checked exceptions.static <T> ToLongFunction<T>toLongFunction(CheckedToLongFunction<T> function) Wrap aCheckedToLongFunctionin aToLongFunction.static <T> ToLongFunction<T>toLongFunction(CheckedToLongFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToLongFunctionin aToLongFunctionwith a custom handler for checked exceptions.static <T> UnaryOperator<T>unaryOperator(CheckedUnaryOperator<T> operator) Wrap aCheckedUnaryOperatorin aUnaryOperator.static <T> UnaryOperator<T>unaryOperator(CheckedUnaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedUnaryOperatorin aUnaryOperatorwith a custom handler for checked exceptions.
-
Field Details
-
THROWABLE_TO_RUNTIME_EXCEPTION
-
RETHROW_ALL
AConsumerthat rethrows all exceptions, including checked exceptions.
-
-
Method Details
-
throwChecked
"sneaky-throw" a checked exception or throwable. -
runnable
Wrap aCheckedRunnablein aRunnable.Example:
new Thread(Unchecked.runnable(() -> { throw new Exception("Cannot run this thread"); })).start(); -
runnable
Wrap aCheckedRunnablein aRunnablewith a custom handler for checked exceptions.Example:
new Thread(Unchecked.runnable( () -> { throw new Exception("Cannot run this thread"); }, e -> { throw new IllegalStateException(e); } )).start(); -
callable
Wrap aCheckedCallable<T>in aCallable<T>.Example:
Executors.newFixedThreadPool(1).submit(Unchecked.callable(() -> { throw new Exception("Cannot execute this task"); })).get(); -
callable
Wrap aCheckedCallable<T>in aCallable<T>with a custom handler for checked exceptions.Example:
Executors.newFixedThreadPool(1).submit(Unchecked.callable( () -> { throw new Exception("Cannot execute this task"); }, e -> { throw new IllegalStateException(e); } )).get(); -
comparator
Wrap aCheckedComparatorin aComparator. -
comparator
public static <T> Comparator<T> comparator(CheckedComparator<T> comparator, Consumer<Throwable> handler) Wrap aCheckedComparatorin aComparatorwith a custom handler for checked exceptions. -
biConsumer
Wrap aCheckedBiConsumerin aBiConsumer.Example:
map.forEach(Unchecked.biConsumer((k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); })); -
biConsumer
public static <T,U> BiConsumer<T,U> biConsumer(CheckedBiConsumer<T, U> consumer, Consumer<Throwable> handler) Wrap aCheckedBiConsumerin aBiConsumerwith a custom handler for checked exceptions.Example:
map.forEach(Unchecked.biConsumer( (k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); }, e -> { throw new IllegalStateException(e); } )); -
objIntConsumer
Wrap aCheckedObjIntConsumerin aObjIntConsumer. -
objIntConsumer
public static <T> ObjIntConsumer<T> objIntConsumer(CheckedObjIntConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjIntConsumerin aObjIntConsumerwith a custom handler for checked exceptions. -
objLongConsumer
Wrap aCheckedObjLongConsumerin aObjLongConsumer. -
objLongConsumer
public static <T> ObjLongConsumer<T> objLongConsumer(CheckedObjLongConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjLongConsumerin aObjLongConsumerwith a custom handler for checked exceptions. -
objDoubleConsumer
Wrap aCheckedObjDoubleConsumerin aObjDoubleConsumer. -
objDoubleConsumer
public static <T> ObjDoubleConsumer<T> objDoubleConsumer(CheckedObjDoubleConsumer<T> consumer, Consumer<Throwable> handler) Wrap aCheckedObjDoubleConsumerin aObjDoubleConsumerwith a custom handler for checked exceptions. -
biFunction
Wrap aCheckedBiFunctionin aBiFunction.Example:
map.computeIfPresent("key", Unchecked.biFunction((k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); return 42; })); -
biFunction
public static <T,U, BiFunction<T,R> U, biFunctionR> (CheckedBiFunction<T, U, R> function, Consumer<Throwable> handler) Wrap aCheckedBiFunctionin aBiFunctionwith a custom handler for checked exceptions.Example:
map.computeIfPresent("key", Unchecked.biFunction( (k, v) -> { if (k == null || v == null) throw new Exception("No nulls allowed in map"); return 42; }, e -> { throw new IllegalStateException(e); } )); -
toIntBiFunction
Wrap aCheckedToIntBiFunctionin aToIntBiFunction. -
toIntBiFunction
public static <T,U> ToIntBiFunction<T,U> toIntBiFunction(CheckedToIntBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToIntBiFunctionin aToIntBiFunctionwith a custom handler for checked exceptions. -
toLongBiFunction
Wrap aCheckedToLongBiFunctionin aToLongBiFunction. -
toLongBiFunction
public static <T,U> ToLongBiFunction<T,U> toLongBiFunction(CheckedToLongBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToLongBiFunctionin aToLongBiFunctionwith a custom handler for checked exceptions. -
toDoubleBiFunction
public static <T,U> ToDoubleBiFunction<T,U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function) Wrap aCheckedToDoubleBiFunctionin aToDoubleBiFunction. -
toDoubleBiFunction
public static <T,U> ToDoubleBiFunction<T,U> toDoubleBiFunction(CheckedToDoubleBiFunction<T, U> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleBiFunctionin aToDoubleBiFunctionwith a custom handler for checked exceptions. -
biPredicate
Wrap aCheckedBiPredicatein aBiPredicate. -
biPredicate
public static <T,U> BiPredicate<T,U> biPredicate(CheckedBiPredicate<T, U> predicate, Consumer<Throwable> handler) Wrap aCheckedBiPredicatein aBiPredicatewith a custom handler for checked exceptions. -
binaryOperator
Wrap aCheckedBinaryOperatorin aBinaryOperator.Example:
Stream.of("a", "b", "c").reduce(Unchecked.binaryOperator((s1, s2) -> { if (s2.length() > 10) throw new Exception("Only short strings allowed"); return s1 + s2; })); -
binaryOperator
public static <T> BinaryOperator<T> binaryOperator(CheckedBinaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedBinaryOperatorin aBinaryOperatorwith a custom handler for checked exceptions.Example:
Stream.of("a", "b", "c").reduce(Unchecked.binaryOperator( (s1, s2) -> { if (s2.length() > 10) throw new Exception("Only short strings allowed"); return s1 + s2; }, e -> { throw new IllegalStateException(e); } )); -
intBinaryOperator
Wrap aCheckedIntBinaryOperatorin aIntBinaryOperator.Example:
IntStream.of(1, 2, 3).reduce(Unchecked.intBinaryOperator((i1, i2) -> { if (i2 < 0) throw new Exception("Only positive numbers allowed"); return i1 + i2; })); -
intBinaryOperator
public static IntBinaryOperator intBinaryOperator(CheckedIntBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntBinaryOperatorin aIntBinaryOperatorwith a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).reduce(Unchecked.intBinaryOperator( (i1, i2) -> { if (i2 < 0) throw new Exception("Only positive numbers allowed"); return i1 + i2; }, e -> { throw new IllegalStateException(e); } )); -
longBinaryOperator
Wrap aCheckedLongBinaryOperatorin aLongBinaryOperator.Example:
LongStream.of(1L, 2L, 3L).reduce(Unchecked.longBinaryOperator((l1, l2) -> { if (l2 < 0L) throw new Exception("Only positive numbers allowed"); return l1 + l2; })); -
longBinaryOperator
public static LongBinaryOperator longBinaryOperator(CheckedLongBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongBinaryOperatorin aLongBinaryOperatorwith a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).reduce(Unchecked.longBinaryOperator( (l1, l2) -> { if (l2 < 0L) throw new Exception("Only positive numbers allowed"); return l1 + l2; }, e -> { throw new IllegalStateException(e); } )); -
doubleBinaryOperator
Wrap aCheckedDoubleBinaryOperatorin aDoubleBinaryOperator.Example:
DoubleStream.of(1.0, 2.0, 3.0).reduce(Unchecked.doubleBinaryOperator((d1, d2) -> { if (d2 < 0.0) throw new Exception("Only positive numbers allowed"); return d1 + d2; })); -
doubleBinaryOperator
public static DoubleBinaryOperator doubleBinaryOperator(CheckedDoubleBinaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleBinaryOperatorin aDoubleBinaryOperatorwith a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).reduce(Unchecked.doubleBinaryOperator( (d1, d2) -> { if (d2 < 0.0) throw new Exception("Only positive numbers allowed"); return d1 + d2; }, e -> { throw new IllegalStateException(e); } )); -
consumer
Wrap aCheckedConsumerin aConsumer.Example:
Arrays.asList("a", "b").stream().forEach(Unchecked.consumer(s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); })); -
consumer
Wrap aCheckedConsumerin aConsumerwith a custom handler for checked exceptions.Example:
Arrays.asList("a", "b").stream().forEach(Unchecked.consumer( s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); }, e -> { throw new IllegalStateException(e); } )); -
intConsumer
Wrap aCheckedIntConsumerin aIntConsumer.Example:
Arrays.stream(new int[] { 1, 2 }).forEach(Unchecked.intConsumer(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); })); -
intConsumer
Wrap aCheckedIntConsumerin aIntConsumerwith a custom handler for checked exceptions.Example:
Arrays.stream(new int[] { 1, 2 }).forEach(Unchecked.intConsumer( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); }, e -> { throw new IllegalStateException(e); } )); -
longConsumer
Wrap aCheckedLongConsumerin aLongConsumer.Example:
Arrays.stream(new long[] { 1L, 2L }).forEach(Unchecked.longConsumer(l -> { if (l < 0) throw new Exception("Only positive numbers allowed"); })); -
longConsumer
Wrap aCheckedLongConsumerin aLongConsumerwith a custom handler for checked exceptions.Example:
Arrays.stream(new long[] { 1L, 2L }).forEach(Unchecked.longConsumer( l -> { if (l < 0) throw new Exception("Only positive numbers allowed"); }, e -> { throw new IllegalStateException(e); } )); -
doubleConsumer
Wrap aCheckedDoubleConsumerin aDoubleConsumer.Example:
Arrays.stream(new double[] { 1.0, 2.0 }).forEach(Unchecked.doubleConsumer(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); })); -
doubleConsumer
public static DoubleConsumer doubleConsumer(CheckedDoubleConsumer consumer, Consumer<Throwable> handler) Wrap aCheckedDoubleConsumerin aDoubleConsumerwith a custom handler for checked exceptions.Example:
Arrays.stream(new double[] { 1.0, 2.0 }).forEach(Unchecked.doubleConsumer( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); }, e -> { throw new IllegalStateException(e); } )); -
function
Wrap aCheckedFunctionin aFunction.Example:
map.computeIfAbsent("key", Unchecked.function(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; })); -
function
public static <T,R> Function<T,R> function(CheckedFunction<T, R> function, Consumer<Throwable> handler) Wrap aCheckedFunctionin aFunctionwith a custom handler for checked exceptions.Example:
map.forEach(Unchecked.function( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }, e -> { throw new IllegalStateException(e); } )); -
toIntFunction
Wrap aCheckedToIntFunctionin aToIntFunction.Example:
map.computeIfAbsent("key", Unchecked.toIntFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; })); -
toIntFunction
public static <T> ToIntFunction<T> toIntFunction(CheckedToIntFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToIntFunctionin aToIntFunctionwith a custom handler for checked exceptions.Example:
map.forEach(Unchecked.toIntFunction( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42; }, e -> { throw new IllegalStateException(e); } )); -
toLongFunction
Wrap aCheckedToLongFunctionin aToLongFunction.Example:
map.computeIfAbsent("key", Unchecked.toLongFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42L; })); -
toLongFunction
public static <T> ToLongFunction<T> toLongFunction(CheckedToLongFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToLongFunctionin aToLongFunctionwith a custom handler for checked exceptions.Example:
map.forEach(Unchecked.toLongFunction( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42L; }, e -> { throw new IllegalStateException(e); } )); -
toDoubleFunction
Wrap aCheckedToDoubleFunctionin aToDoubleFunction.Example:
map.computeIfAbsent("key", Unchecked.toDoubleFunction(k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42.0; })); -
toDoubleFunction
public static <T> ToDoubleFunction<T> toDoubleFunction(CheckedToDoubleFunction<T> function, Consumer<Throwable> handler) Wrap aCheckedToDoubleFunctionin aToDoubleFunctionwith a custom handler for checked exceptions.Example:
map.forEach(Unchecked.toDoubleFunction( k -> { if (k.length() > 10) throw new Exception("Only short strings allowed"); return 42.0; }, e -> { throw new IllegalStateException(e); } )); -
intFunction
Wrap aCheckedIntFunctionin aIntFunction.Example:
IntStream.of(1, 2, 3).mapToObj(Unchecked.intFunction(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return "" + i; }); -
intFunction
public static <R> IntFunction<R> intFunction(CheckedIntFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedIntFunctionin aIntFunctionwith a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).mapToObj(Unchecked.intFunction( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return "" + i; }, e -> { throw new IllegalStateException(e); } )); -
intToLongFunction
Wrap aCheckedIntToLongFunctionin aIntToLongFunction.Example:
IntStream.of(1, 2, 3).mapToLong(Unchecked.intToLongFunction(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (long) i; }); -
intToLongFunction
public static IntToLongFunction intToLongFunction(CheckedIntToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToLongFunctionin aIntToLongFunctionwith a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).mapToLong(Unchecked.intToLongFunction( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (long) i; }, e -> { throw new IllegalStateException(e); } )); -
intToDoubleFunction
Wrap aCheckedIntToDoubleFunctionin aIntToDoubleFunction.Example:
IntStream.of(1, 2, 3).mapToDouble(Unchecked.intToDoubleFunction(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (double) i; }); -
intToDoubleFunction
public static IntToDoubleFunction intToDoubleFunction(CheckedIntToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedIntToDoubleFunctionin aIntToDoubleFunctionwith a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).mapToDouble(Unchecked.intToDoubleFunction( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return (double) i; }, e -> { throw new IllegalStateException(e); } )); -
longFunction
Wrap aCheckedLongFunctionin aLongFunction.Example:
LongStream.of(1L, 2L, 3L).mapToObj(Unchecked.longFunction(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return "" + l; }); -
longFunction
public static <R> LongFunction<R> longFunction(CheckedLongFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedLongFunctionin aLongFunctionwith a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).mapToObj(Unchecked.longFunction( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return "" + l; }, e -> { throw new IllegalStateException(e); } )); -
longToIntFunction
Wrap aCheckedLongToIntFunctionin aLongToIntFunction.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToIntFunction(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (int) l; }); -
longToIntFunction
public static LongToIntFunction longToIntFunction(CheckedLongToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToIntFunctionin aLongToIntFunctionwith a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToIntFunction( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (int) l; }, e -> { throw new IllegalStateException(e); } )); -
longToDoubleFunction
Wrap aCheckedLongToDoubleFunctionin aLongToDoubleFunction.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToDoubleFunction(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (double) l; }); -
longToDoubleFunction
public static LongToDoubleFunction longToDoubleFunction(CheckedLongToDoubleFunction function, Consumer<Throwable> handler) Wrap aCheckedLongToDoubleFunctionin aLongToDoubleFunctionwith a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).mapToInt(Unchecked.longToDoubleFunction( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return (double) l; }, e -> { throw new IllegalStateException(e); } )); -
doubleFunction
Wrap aCheckedDoubleFunctionin aDoubleFunction.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToObj(Unchecked.doubleFunction(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return "" + d; }); -
doubleFunction
public static <R> DoubleFunction<R> doubleFunction(CheckedDoubleFunction<R> function, Consumer<Throwable> handler) Wrap aCheckedDoubleFunctionin aDoubleFunctionwith a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToObj(Unchecked.doubleFunction( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return "" + d; }, e -> { throw new IllegalStateException(e); } )); -
doubleToIntFunction
Wrap aCheckedDoubleToIntFunctionin aDoubleToIntFunction.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToInt(Unchecked.doubleToIntFunction(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (int) d; }); -
doubleToIntFunction
public static DoubleToIntFunction doubleToIntFunction(CheckedDoubleToIntFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToIntFunctionin aDoubleToIntFunctionwith a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToInt(Unchecked.doubleToIntFunction( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (int) d; }, e -> { throw new IllegalStateException(e); } )); -
doubleToLongFunction
Wrap aCheckedDoubleToLongFunctionin aDoubleToLongFunction.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToLong(Unchecked.doubleToLongFunction(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (long) d; }); -
doubleToLongFunction
public static DoubleToLongFunction doubleToLongFunction(CheckedDoubleToLongFunction function, Consumer<Throwable> handler) Wrap aCheckedDoubleToLongFunctionin aDoubleToLongFunctionwith a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).mapToLong(Unchecked.doubleToLongFunction( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return (long) d; }, e -> { throw new IllegalStateException(e); } )); -
predicate
Wrap aCheckedPredicatein aPredicate.Example:
Stream.of("a", "b", "c").filter(Unchecked.predicate(s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return true; })); -
predicate
Wrap aCheckedPredicatein aPredicatewith a custom handler for checked exceptions.Example:
Stream.of("a", "b", "c").filter(Unchecked.predicate( s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return true; }, e -> { throw new IllegalStateException(e); } )); -
intPredicate
Wrap aCheckedPredicatein aIntPredicate.Example:
IntStream.of(1, 2, 3).filter(Unchecked.intPredicate(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return true; })); -
intPredicate
Wrap aCheckedPredicatein aIntPredicatewith a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).filter(Unchecked.intPredicate( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return true; }, e -> { throw new IllegalStateException(e); } )); -
longPredicate
Wrap aCheckedLongPredicatein aLongPredicate.Example:
LongStream.of(1L, 2L, 3L).filter(Unchecked.longPredicate(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return true; })); -
longPredicate
public static LongPredicate longPredicate(CheckedLongPredicate function, Consumer<Throwable> handler) Wrap aCheckedLongPredicatein aLongPredicatewith a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).filter(Unchecked.longPredicate( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return true; }, e -> { throw new IllegalStateException(e); } )); -
doublePredicate
Wrap aCheckedDoublePredicatein aDoublePredicate.Example:
DoubleStream.of(1.0, 2.0, 3.0).filter(Unchecked.doublePredicate(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return true; })); -
doublePredicate
public static DoublePredicate doublePredicate(CheckedDoublePredicate function, Consumer<Throwable> handler) Wrap aCheckedDoublePredicatein aDoublePredicatewith a custom handler for checked exceptions.Example:
DoubleStream.of(1.0, 2.0, 3.0).filter(Unchecked.doublePredicate( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return true; }, e -> { throw new IllegalStateException(e); } )); -
supplier
Wrap aCheckedSupplierin aSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.supplier(() -> rs.getObject(1))); -
supplier
Wrap aCheckedSupplierin aSupplierwith a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.supplier( () -> rs.getObject(1), e -> { throw new IllegalStateException(e); } )); -
intSupplier
Wrap aCheckedIntSupplierin aIntSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.intSupplier(() -> rs.getInt(1))); -
intSupplier
Wrap aCheckedIntSupplierin aIntSupplierwith a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.intSupplier( () -> rs.getInt(1), e -> { throw new IllegalStateException(e); } )); -
longSupplier
Wrap aCheckedLongSupplierin aLongSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.longSupplier(() -> rs.getLong(1))); -
longSupplier
Wrap aCheckedLongSupplierin aLongSupplierwith a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.longSupplier( () -> rs.getLong(1), e -> { throw new IllegalStateException(e); } )); -
doubleSupplier
Wrap aCheckedDoubleSupplierin aDoubleSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.doubleSupplier(() -> rs.getDouble(1))); -
doubleSupplier
public static DoubleSupplier doubleSupplier(CheckedDoubleSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedDoubleSupplierin aDoubleSupplierwith a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.doubleSupplier( () -> rs.getDouble(1), e -> { throw new IllegalStateException(e); } )); -
booleanSupplier
Wrap aCheckedBooleanSupplierin aBooleanSupplier.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.booleanSupplier(() -> rs.getBoolean(1))); -
booleanSupplier
public static BooleanSupplier booleanSupplier(CheckedBooleanSupplier supplier, Consumer<Throwable> handler) Wrap aCheckedBooleanSupplierin aBooleanSupplierwith a custom handler for checked exceptions.Example:
ResultSet rs = statement.executeQuery(); Stream.generate(Unchecked.booleanSupplier( () -> rs.getBoolean(1), e -> { throw new IllegalStateException(e); } )); -
unaryOperator
Wrap aCheckedUnaryOperatorin aUnaryOperator.Example:
Stream.of("a", "b", "c").map(Unchecked.unaryOperator(s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return s; })); -
unaryOperator
public static <T> UnaryOperator<T> unaryOperator(CheckedUnaryOperator<T> operator, Consumer<Throwable> handler) Wrap aCheckedUnaryOperatorin aUnaryOperatorwith a custom handler for checked exceptions.Example:
Stream.of("a", "b", "c").map(Unchecked.unaryOperator( s -> { if (s.length() > 10) throw new Exception("Only short strings allowed"); return s; }, e -> { throw new IllegalStateException(e); } )); -
intUnaryOperator
Wrap aCheckedIntUnaryOperatorin aIntUnaryOperator.Example:
IntStream.of(1, 2, 3).map(Unchecked.intUnaryOperator(i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return i; })); -
intUnaryOperator
public static IntUnaryOperator intUnaryOperator(CheckedIntUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedIntUnaryOperatorin aIntUnaryOperatorwith a custom handler for checked exceptions.Example:
IntStream.of(1, 2, 3).map(Unchecked.intUnaryOperator( i -> { if (i < 0) throw new Exception("Only positive numbers allowed"); return i; }, e -> { throw new IllegalStateException(e); } )); -
longUnaryOperator
Wrap aCheckedLongUnaryOperatorin aLongUnaryOperator.Example:
LongStream.of(1L, 2L, 3L).map(Unchecked.longUnaryOperator(l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return l; })); -
longUnaryOperator
public static LongUnaryOperator longUnaryOperator(CheckedLongUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedLongUnaryOperatorin aLongUnaryOperatorwith a custom handler for checked exceptions.Example:
LongStream.of(1L, 2L, 3L).map(Unchecked.longUnaryOperator( l -> { if (l < 0L) throw new Exception("Only positive numbers allowed"); return l; }, e -> { throw new IllegalStateException(e); } )); -
doubleUnaryOperator
Wrap aCheckedDoubleUnaryOperatorin aDoubleUnaryOperator.Example:
LongStream.of(1.0, 2.0, 3.0).map(Unchecked.doubleUnaryOperator(d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return d; })); -
doubleUnaryOperator
public static DoubleUnaryOperator doubleUnaryOperator(CheckedDoubleUnaryOperator operator, Consumer<Throwable> handler) Wrap aCheckedDoubleUnaryOperatorin aDoubleUnaryOperatorwith a custom handler for checked exceptions.Example:
LongStream.of(1.0, 2.0, 3.0).map(Unchecked.doubleUnaryOperator( d -> { if (d < 0.0) throw new Exception("Only positive numbers allowed"); return d; }, e -> { throw new IllegalStateException(e); } ));
-