Class ExceptionHelper

java.lang.Object
io.reactivex.rxjava3.internal.util.ExceptionHelper

public final class ExceptionHelper extends Object
Terminal atomics for Throwable containers.
  • Field Details

    • TERMINATED

      public static final Throwable TERMINATED
      A singleton instance of a Throwable indicating a terminal state for exceptions, don't leak this.
  • Constructor Details

    • ExceptionHelper

      private ExceptionHelper()
      Utility class.
  • Method Details

    • wrapOrThrow

      public static RuntimeException wrapOrThrow(Throwable error)
      If the provided Throwable is an Error this method throws it, otherwise returns a RuntimeException wrapping the error if that error is a checked exception.
      Parameters:
      error - the error to wrap or throw
      Returns:
      the (wrapped) error
    • addThrowable

      public static boolean addThrowable(AtomicReference<Throwable> field, Throwable exception)
    • terminate

      public static Throwable terminate(AtomicReference<Throwable> field)
    • flatten

      public static List<Throwable> flatten(Throwable t)
      Returns a flattened list of Throwables from tree-like CompositeException chain.
      Parameters:
      t - the starting throwable
      Returns:
      the list of Throwables flattened in a depth-first manner
    • throwIfThrowable

      public static <E extends Throwable> Exception throwIfThrowable(Throwable e) throws E
      Workaround for Java 6 not supporting throwing a final Throwable from a catch block.
      Type Parameters:
      E - the generic exception type
      Parameters:
      e - the Throwable error to return or throw
      Returns:
      the Throwable e if it is a subclass of Exception
      Throws:
      E - the generic exception thrown
    • timeoutMessage

      public static String timeoutMessage(long timeout, TimeUnit unit)
    • nullWarning

      public static String nullWarning(String prefix)
      Composes a String with a null warning message.
      Parameters:
      prefix - the prefix to add to the message.
      Returns:
      the composed String
      Since:
      3.0.0
    • createNullPointerException

      public static NullPointerException createNullPointerException(String prefix)
      Creates a NullPointerException with a composed message via nullWarning(String).
      Parameters:
      prefix - the prefix to add to the message.
      Returns:
      the composed String
      Since:
      3.0.0
    • nullCheck

      public static <T> T nullCheck(T value, String prefix)
      Similar to Objects.requireNonNull but composes the error message via nullWarning(String).
      Type Parameters:
      T - the value type
      Parameters:
      value - the value to check
      prefix - the prefix to the error message
      Returns:
      the value
      Throws:
      NullPointerException - if value is null
      Since:
      3.0.0