java.lang.Object
is.codion.common.utilities.exceptions.Exceptions

public final class Exceptions extends Object
Exception handling utilities.
  • Method Details

    • runtime

      public static RuntimeException runtime(Throwable throwable)

      Returns the given Throwable in case it is a RuntimeException or else a RuntimeException wrapping it.

      Note that if a new wrapper RuntimeException is created, it has the stacktrace of the original throwable, as well as its message, while keeping the original throwable as its cause.

      Parameters:
      throwable - the throwable
      Returns:
      the throwable itself if it is a RuntimeException, otherwise a RuntimeException wrapping it
    • runtime

      @SafeVarargs public static RuntimeException runtime(Throwable throwable, Class<? extends Throwable>... unwrap)

      Returns the given Throwable in case it is a RuntimeException or else a RuntimeException wrapping it.

      Note that if a new wrapper RuntimeException is created, it has the stacktrace of the unwrapped throwable, as well as its message, while keeping the unwrapped throwable as its cause.

      Parameters:
      throwable - the throwable
      unwrap - the exception types to unwrap before wrapping
      Returns:
      the unwrapped throwable itself if it is a RuntimeException, otherwise a RuntimeException wrapping it
    • unwrap

      public static Throwable unwrap(Throwable throwable, Collection<Class<? extends Throwable>> unwrap)
      Unwraps the given throwable, following the cause chain while each cause's exact class is one of the given types. Note that matching is by exact class; subclasses of a listed type are not unwrapped.
      Parameters:
      throwable - the exception to unwrap
      unwrap - the exception types to unwrap
      Returns:
      the unwrapped exception