Skip to content

Commit

Permalink
sneakyThrow.
Browse files Browse the repository at this point in the history
  • Loading branch information
mihxil committed Sep 25, 2024
1 parent 49f1b13 commit b41d4f2
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions vpro-shared-util/src/main/java/nl/vpro/util/ExceptionUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static <T> Supplier<T> wrapException(Callable<T> b) {
try {
return b.call();
} catch (Throwable t) {
throw Lombok.sneakyThrow(t);
throw sneakyThrow(t);
}
};
}
Expand All @@ -42,7 +42,7 @@ public static <A, R, E extends Exception> Function<A, R> wrapException(ThrowingF
try {
return f.apply(a);
} catch (Throwable t) {
throw Lombok.sneakyThrow(t);
throw sneakyThrow(t);
}
};
}
Expand Down Expand Up @@ -98,4 +98,17 @@ default R apply(A a) {
R applyWithException(A a) throws E;
}

/**
* Exactly like {@link Lombok#sneakyThrow(Throwable)}, but without the lombok dependencyh
*/
public static RuntimeException sneakyThrow(Throwable t) {
if (t == null) throw new NullPointerException("t");
return sneakyThrow0(t);
}

@SuppressWarnings("unchecked")
private static <T extends Throwable> T sneakyThrow0(Throwable t) throws T {
throw (T)t;
}

}

0 comments on commit b41d4f2

Please sign in to comment.