Class SneakyThrow

java.lang.Object
com.hypixel.hytale.sneakythrow.SneakyThrow

public class SneakyThrow extends Object
Based off of https://github.com/rzwitserloot/lombok/blob/5a2fe6e61caf9024be29568b0b053f163c6f899e/src/core/lombok/Lombok.java#L28-L57
  • Constructor Details

    • SneakyThrow

      public SneakyThrow()
  • Method Details

    • sneakyThrow

      @Nonnull public static RuntimeException sneakyThrow(@Nonnull Throwable t)
      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 the throw statement to avoid compiler errors regarding no return statement and similar problems. This method won't of course return an actual RuntimeException - 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

      public static <E extends Throwable> Runnable sneakyRunnable(ThrowableRunnable<E> runnable)
    • sneakySupplier

      public static <T, E extends Throwable> Supplier<T> sneakySupplier(ThrowableSupplier<T,E> supplier)
    • sneakySupplier

      public static <E extends Throwable> IntSupplier sneakySupplier(ThrowableIntSupplier<E> supplier)
    • sneakyConsumer

      public static <T, E extends Throwable> Consumer<T> sneakyConsumer(ThrowableConsumer<T,E> consumer)
    • 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,V> sneakyConsumer(ThrowableTriConsumer<T,U,V,E> consumer)
    • sneakyIntConsumer

      public static <E extends Throwable> IntConsumer sneakyIntConsumer(ThrowableIntConsumer<E> consumer)
    • 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,R> sneakyFunction(ThrowableBiFunction<T,U,R,E> function)