Skip to content

Commit f812b30

Browse files
author
Grzegorz Piwowarek
committed
Extend Throwable and not Exception
1 parent abadb51 commit f812b30

10 files changed

+22
-22
lines changed

src/main/java/pl/touk/throwing/ThrowingBiConsumer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* @see ThrowingConsumer
1717
*/
1818
@FunctionalInterface
19-
public interface ThrowingBiConsumer<T, U, E extends Exception> {
19+
public interface ThrowingBiConsumer<T, U, E extends Throwable> {
2020
void accept(T t, U u) throws E;
2121

2222
default ThrowingBiConsumer<T, U, E> andThenConsume(final ThrowingBiConsumer<? super T, ? super U, E> after) {
@@ -53,7 +53,7 @@ default BiConsumer<T, U> unchecked() {
5353
return (arg1, arg2) -> {
5454
try {
5555
accept(arg1, arg2);
56-
} catch (final Exception e) {
56+
} catch (final Throwable e) {
5757
throw new RuntimeException(e);
5858
}
5959
};

src/main/java/pl/touk/throwing/ThrowingBiFunction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
* @see ThrowingFunction
1818
*/
1919
@FunctionalInterface
20-
public interface ThrowingBiFunction<T1, T2, R, E extends Exception> {
20+
public interface ThrowingBiFunction<T1, T2, R, E extends Throwable> {
2121
R apply(T1 arg1, T2 arg2) throws E;
2222

2323
/**
@@ -32,7 +32,7 @@ default <V> ThrowingBiFunction<T1, T2, V, E> andThen(final ThrowingFunction<? su
3232
return (arg1, arg2) -> after.apply(apply(arg1, arg2));
3333
}
3434

35-
static <T1, T2, R, E extends Exception> BiFunction<T1, T2, R> unchecked(ThrowingBiFunction<T1, T2, R, E> function) {
35+
static <T1, T2, R, E extends Throwable> BiFunction<T1, T2, R> unchecked(ThrowingBiFunction<T1, T2, R, E> function) {
3636
Objects.requireNonNull(function);
3737

3838
return function.unchecked();
@@ -42,7 +42,7 @@ default BiFunction<T1, T2, R> unchecked() {
4242
return (arg1, arg2) -> {
4343
try {
4444
return apply(arg1, arg2);
45-
} catch (final Exception e) {
45+
} catch (final Throwable e) {
4646
throw new RuntimeException(e);
4747
}
4848
};

src/main/java/pl/touk/throwing/ThrowingBiPredicate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @param <E> the type of the thrown checked exception
1414
*/
1515
@FunctionalInterface
16-
public interface ThrowingBiPredicate<T, U, E extends Exception> {
16+
public interface ThrowingBiPredicate<T, U, E extends Throwable> {
1717
boolean test(T t, U u) throws E;
1818

1919
default ThrowingBiPredicate<T, U, E> and(final ThrowingBiPredicate<? super T, ? super U, E> other) {
@@ -58,7 +58,7 @@ default BiPredicate<T, U> unchecked() {
5858
return (arg1, arg2) -> {
5959
try {
6060
return test(arg1, arg2);
61-
} catch (final Exception e) {
61+
} catch (final Throwable e) {
6262
throw new RuntimeException(e);
6363
}
6464
};

src/main/java/pl/touk/throwing/ThrowingBinaryOperator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
* @see ThrowingBiFunction
1919
* @see ThrowingUnaryOperator
2020
*/
21-
public interface ThrowingBinaryOperator<T, E extends Exception> extends ThrowingBiFunction<T, T, T, E> {
21+
public interface ThrowingBinaryOperator<T, E extends Throwable> extends ThrowingBiFunction<T, T, T, E> {
2222

2323
static <T, E extends Exception> ThrowingBinaryOperator<T, E> minBy(Comparator<? super T> comparator) {
2424
Objects.requireNonNull(comparator);

src/main/java/pl/touk/throwing/ThrowingConsumer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*/
1414
@FunctionalInterface
15-
public interface ThrowingConsumer<T, E extends Exception> {
15+
public interface ThrowingConsumer<T, E extends Throwable> {
1616

1717
void accept(T t) throws E;
1818

@@ -40,7 +40,7 @@ default ThrowingFunction<T, Void, E> asFunction() {
4040
};
4141
}
4242

43-
static <T, E extends Exception> Consumer<T> unchecked(ThrowingConsumer<T, E> consumer) {
43+
static <T, E extends Throwable> Consumer<T> unchecked(ThrowingConsumer<T, E> consumer) {
4444
Objects.requireNonNull(consumer);
4545

4646
return consumer.unchecked();
@@ -53,7 +53,7 @@ default Consumer<T> unchecked() {
5353
return t -> {
5454
try {
5555
accept(t);
56-
} catch (final Exception e) {
56+
} catch (final Throwable e) {
5757
throw new RuntimeException(e);
5858
}
5959
};

src/main/java/pl/touk/throwing/ThrowingFunction.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717
@FunctionalInterface
18-
public interface ThrowingFunction<T,R,E extends Exception> {
18+
public interface ThrowingFunction<T,R,E extends Throwable> {
1919
R apply(T arg) throws E;
2020

2121
/**
@@ -47,7 +47,7 @@ default Function<T, Optional<R>> returningOptional() {
4747
return t -> {
4848
try {
4949
return Optional.of(apply(t));
50-
} catch (Exception e) {
50+
} catch (Throwable e) {
5151
return Optional.empty();
5252
}
5353
};
@@ -66,7 +66,7 @@ default Function<T, R> unchecked() {
6666
return t -> {
6767
try {
6868
return apply(t);
69-
} catch (final Exception e) {
69+
} catch (final Throwable e) {
7070
throw new RuntimeException(e);
7171
}
7272
};

src/main/java/pl/touk/throwing/ThrowingPredicate.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
*/
1515
@FunctionalInterface
16-
public interface ThrowingPredicate<T, E extends Exception> {
16+
public interface ThrowingPredicate<T, E extends Throwable> {
1717
boolean test(T t) throws E;
1818

1919
default ThrowingPredicate<T, E> and(final ThrowingPredicate<? super T, E> other) {
@@ -68,7 +68,7 @@ default Predicate<T> unchecked() {
6868
return t -> {
6969
try {
7070
return test(t);
71-
} catch (final Exception e) {
71+
} catch (final Throwable e) {
7272
throw new RuntimeException(e);
7373
}
7474
};

src/main/java/pl/touk/throwing/ThrowingRunnable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* @param <E> the type of the thrown checked exception
1010
*/
1111
@FunctionalInterface
12-
public interface ThrowingRunnable<E extends Exception> {
12+
public interface ThrowingRunnable<E extends Throwable> {
1313
void run() throws E;
1414

1515
static <E extends Exception> Runnable unchecked(ThrowingRunnable<E> runnable) {
@@ -25,7 +25,7 @@ default Runnable unchecked() {
2525
return () -> {
2626
try {
2727
run();
28-
} catch (final Exception e) {
28+
} catch (final Throwable e) {
2929
throw new RuntimeException(e);
3030
}
3131
};

src/main/java/pl/touk/throwing/ThrowingSupplier.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*
1313
*/
1414
@FunctionalInterface
15-
public interface ThrowingSupplier<T, E extends Exception> {
15+
public interface ThrowingSupplier<T, E extends Throwable> {
1616
T get() throws E;
1717

1818
/**
@@ -45,7 +45,7 @@ default Supplier<T> unchecked() {
4545
return () -> {
4646
try {
4747
return get();
48-
} catch (final Exception e) {
48+
} catch (final Throwable e) {
4949
throw new RuntimeException(e);
5050
}
5151
};

src/main/java/pl/touk/throwing/ThrowingUnaryOperator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @see ThrowingFunction
1616
*/
1717
@FunctionalInterface
18-
public interface ThrowingUnaryOperator<T, E extends Exception> extends ThrowingFunction<T, T, E> {
18+
public interface ThrowingUnaryOperator<T, E extends Throwable> extends ThrowingFunction<T, T, E> {
1919

2020
static <T, E extends Exception> UnaryOperator<T> unchecked(ThrowingUnaryOperator<T, E> operator) {
2121
Objects.requireNonNull(operator);
@@ -30,7 +30,7 @@ default UnaryOperator<T> unchecked() {
3030
return t -> {
3131
try {
3232
return apply(t);
33-
} catch (final Exception e) {
33+
} catch (final Throwable e) {
3434
throw new RuntimeException(e);
3535
}
3636
};

0 commit comments

Comments
 (0)