Class Exceptions

java.lang.Object
com.mastfrog.util.preconditions.Exceptions

public final class Exceptions extends Object
Simple utilities for dealing with exceptions.
Author:
Tim Boudreau
  • Method Details

    • printStackTrace

      public static void printStackTrace(String msg, Throwable t)
    • printStackTrace

      public static void printStackTrace(Class<?> caller, String msg, Throwable t)
    • printStackTrace

      public static void printStackTrace(Class<?> caller, Throwable t)
    • printStackTrace

      public static void printStackTrace(Throwable t)
    • chuck

      public static <ReturnType> ReturnType chuck(Throwable t)
      Dirty trick to rethrow a checked exception. Makes it possible to implement an interface such as Iterable (which cannot throw exceptions) without the useless re-wrapping of exceptions in RuntimeException.
      Parameters:
      t - A throwable. This method will throw it without requiring a catch block.
    • chuck

      public static <T extends Throwable> void chuck(Class<T> type, Throwable t) throws T
      Throws:
      T extends Throwable
    • chuckUnless

      public static <ReturnType> ReturnType chuckUnless(Throwable t, ReturnType what, BooleanSupplier predicate)
    • chuckOriginal

      public static <ReturnType> ReturnType chuckOriginal(Throwable t)
      Unwinds any causing-exception and chucks the root cause throwable.
      Type Parameters:
      ReturnType - The type to pretend to return (this method always exits abnormally), so methods can be written cleanly, e.g. return Exceptions.chuck(someException).
      Parameters:
      t -
      Returns: