public final class Throwing extends Object
Modifier and Type | Method and Description |
---|---|
static <T extends Throwable> |
rethrow(Throwable t)
Rethrows the specified throwable.
|
static <T,U> BiConsumer<T,U> |
rethrow(ThrowingBiConsumer<T,U,?> consumer)
Rethrows the checked exception from the specified
ThrowingBiConsumer . |
static <T,U,R> BiFunction<T,U,R> |
rethrow(ThrowingBiFunction<T,U,R,?> function)
Rethrows the checked exception from the specified
ThrowingBiFunction . |
static <T,U> BiPredicate<T,U> |
rethrow(ThrowingBiPredicate<T,U,?> predicate)
Rethrows the checked exception from the specified
ThrowingBiPredicate . |
static <T> Consumer<T> |
rethrow(ThrowingConsumer<T,?> consumer)
Rethrows the checked exception from the specified
ThrowingConsumer . |
static <T,R> Function<T,R> |
rethrow(ThrowingFunction<T,R,?> function)
Rethrows the checked exception from the specified
ThrowingFunction . |
static <T> Predicate<T> |
rethrow(ThrowingPredicate<T,?> predicate)
Rethrows the checked exception from the specified
ThrowingConsumer . |
static Runnable |
rethrow(ThrowingRunnable<?> runnable)
Rethrows the checked exception from the specified
ThrowingRunnable . |
static <T> Supplier<T> |
rethrow(ThrowingSupplier<T,?> supplier)
Rethrows the checked exception from the specified
ThrowingSupplier . |
static <T,U,V> TriConsumer<T,U,V> |
rethrow(ThrowingTriConsumer<T,U,V,?> consumer)
Rethrows the checked exception from the specified
ThrowingTriConsumer . |
public static Runnable rethrow(ThrowingRunnable<?> runnable)
ThrowingRunnable
.
An example of this pattern:
Runnable runnable = Throwing.rethrow(() -> {
if (true)
throw new IOException();
});
runnable.run();
runnable
- The ThrowingRunnable
.Runnable
instance.public static <T> Supplier<T> rethrow(ThrowingSupplier<T,?> supplier)
ThrowingSupplier
.
An example of this pattern:
Supplier<String> supplier = Throwing.rethrow(() -> {
if (true)
throw new IOException();
return "hello world";
});
supplier.get();
T
- The type of results supplied by this supplier.supplier
- The ThrowingSupplier
.Supplier
instance.public static <T> Consumer<T> rethrow(ThrowingConsumer<T,?> consumer)
ThrowingConsumer
.
An example of this pattern:
Arrays.asList(2, 1, 0).forEach(Throwing.rethrow(i -> {
if (i == 0)
throw new IllegalArgumentException("i=" + i);
}));
T
- The type of the input to the consumer's operation.consumer
- The ThrowingConsumer
.Consumer
instance.public static <T,U> BiConsumer<T,U> rethrow(ThrowingBiConsumer<T,U,?> consumer)
ThrowingBiConsumer
.
An example of this pattern:
BiConsumer<Integer,Integer> consumer = Throwing.<Integer,Integer>rethrow((i, j) -> {
if (i == 0)
throw new IllegalArgumentException("i=" + i);
});
for (int i = 3; i >= 0; --i)
consumer.accept(i, -i);
T
- The type of the first input to the consumer's operation.U
- The type of the second input to the consumer's operation.consumer
- The ThrowingBiConsumer
.BiConsumer
instance.public static <T,U,V> TriConsumer<T,U,V> rethrow(ThrowingTriConsumer<T,U,V,?> consumer)
ThrowingTriConsumer
.
An example of this pattern:
TriConsumer<Integer,Integer,Integer> consumer = Throwing.<Integer,Integer,Integer>rethrow((i, j, k) -> {
if (i == 0)
throw new IllegalArgumentException("i=" + i);
});
for (int i = 3; i >= 0; --i)
consumer.accept(i, -i, i);
T
- The type of the first input to the consumer's operation.U
- The type of the second input to the consumer's operation.V
- The type of the third input to the consumer's operation.consumer
- The ThrowingTriConsumer
.TriConsumer
instance.public static <T> Predicate<T> rethrow(ThrowingPredicate<T,?> predicate)
ThrowingConsumer
.
An example of this pattern:
Arrays
.asList(2, 1, 0)
.stream()
.filter(Throwing.<Integer>rethrow(i -> {
if (i == 0)
throw new IOException("i=" + i);
return false;
}))
.collect(Collectors.toList());
T
- The type of the input to the consumer's operation.predicate
- The ThrowingConsumer
.Consumer
instance.public static <T,U> BiPredicate<T,U> rethrow(ThrowingBiPredicate<T,U,?> predicate)
ThrowingBiPredicate
.
An example of this pattern:
BiPredicate<Integer,Integer> predicate = Throwing.<Integer,Integer>rethrow((i, j) -> {
if (i == 0)
throw new IllegalArgumentException("i=" + i);
return false;
});
for (int i = 3; i >= 0; --i)
predicate.accept(i, -i);
T
- The type of the first input to the predicate's operation.U
- The type of the second input to the predicate's operation.predicate
- The ThrowingBiPredicate
.BiPredicate
instance.public static <T,R> Function<T,R> rethrow(ThrowingFunction<T,R,?> function)
ThrowingFunction
.
An example of this pattern:
Arrays
.asList(2, 1, 0)
.stream()
.map(Throwing.rethrow((Integer i) -> {
if (i == 0)
throw new IOException("i=" + i);
return String.valueOf(i);
}))
.forEach(f -> {});
T
- The type of the input to the function's operation.R
- The type of the result of the function's function.function
- The ThrowingFunction
.Function
instance.public static <T,U,R> BiFunction<T,U,R> rethrow(ThrowingBiFunction<T,U,R,?> function)
ThrowingBiFunction
.
An example of this pattern:
BiFunction<Integer,Integer,String> function = Throwing.<Integer,Integer,String>rethrow((i, j) -> {
if (i == 0)
throw new IllegalArgumentException("i=" + i);
return String.valueOf(i);
});
for (int i = 3; i >= 0; --i)
function.accept(i, -i);
T
- The type of the first input to the function's operation.U
- The type of the second input to the function's operation.R
- The type of the result of the function's function.function
- The ThrowingFunction
.Function
instance.Copyright © 2020 LibJ. All rights reserved.