Contents
- Description
- Constructor Summary
- Method Summary
- Constructor Details
- Method Details
- sneakyThrow(Throwable)
- sneakyRunnable(ThrowableRunnable)
- sneakySupplier(ThrowableSupplier)
- sneakySupplier(ThrowableIntSupplier)
- sneakyConsumer(ThrowableConsumer)
- sneakyConsumer(ThrowableBiConsumer)
- sneakyConsumer(ThrowableTriConsumer)
- sneakyIntConsumer(ThrowableIntConsumer)
- sneakyFunction(ThrowableFunction)
- sneakyFunction(ThrowableBiFunction)
Class SneakyThrow
java.lang.Object
com.hypixel.hytale.sneakythrow.SneakyThrow
Based off of https://github.com/rzwitserloot/lombok/blob/5a2fe6e61caf9024be29568b0b053f163c6f899e/src/core/lombok/Lombok.java#L28-L57
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T, U, E extends Throwable>
BiConsumer<T, U> sneakyConsumer(ThrowableBiConsumer<T, U, E> consumer) sneakyConsumer(ThrowableConsumer<T, E> consumer) static <T, U, V, E extends Throwable>
TriConsumer<T, U, V> sneakyConsumer(ThrowableTriConsumer<T, U, V, E> consumer) static <T, U, R, E extends Throwable>
BiFunction<T, U, R> sneakyFunction(ThrowableBiFunction<T, U, R, E> function) sneakyFunction(ThrowableFunction<T, R, E> function) static <E extends Throwable>
IntConsumersneakyIntConsumer(ThrowableIntConsumer<E> consumer) sneakyRunnable(ThrowableRunnable<E> runnable) static <E extends Throwable>
IntSuppliersneakySupplier(ThrowableIntSupplier<E> supplier) sneakySupplier(ThrowableSupplier<T, E> supplier) static RuntimeExceptionThrows any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards.
-
Constructor Details
-
SneakyThrow
public SneakyThrow()
-
-
Method Details
-
sneakyThrow
Throws any throwable 'sneakily' - you don't need to catch it, nor declare that you throw it onwards. The exception is still thrown - javac will just stop whining about it.Example usage:
public void run() { throw sneakyThrow(new IOException("You don't need to catch me!")); }NB: The exception is not wrapped, ignored, swallowed, or redefined. The JVM actually does not know or care about the concept of a 'checked exception'. All this method does is hide the act of throwing a checked exception from the java compiler.
Note that this method has a return type of
RuntimeException; it is advised you always call this method as argument to thethrowstatement to avoid compiler errors regarding no return statement and similar problems. This method won't of course return an actualRuntimeException- it never returns, it always throws the provided exception.- Parameters:
t- The throwable to throw without requiring you to catch its type.- Returns:
- A dummy RuntimeException; this method never returns normally, it always throws an exception!
-
sneakyRunnable
-
sneakySupplier
-
sneakySupplier
-
sneakyConsumer
-
sneakyConsumer
public static <T, U, E extends Throwable> BiConsumer<T,U> sneakyConsumer(ThrowableBiConsumer<T, U, E> consumer) -
sneakyConsumer
public static <T, U, V, E extends Throwable> TriConsumer<T,U, sneakyConsumerV> (ThrowableTriConsumer<T, U, V, E> consumer) -
sneakyIntConsumer
-
sneakyFunction
public static <T, R, E extends Throwable> Function<T,R> sneakyFunction(ThrowableFunction<T, R, E> function) -
sneakyFunction
public static <T, U, R, E extends Throwable> BiFunction<T,U, sneakyFunctionR> (ThrowableBiFunction<T, U, R, E> function)
-