Package rx.exceptions

Class Exceptions

java.lang.Object
rx.exceptions.Exceptions

public final class Exceptions extends Object
Utility class with methods to wrap checked exceptions and manage fatal and regular exception delivery.
  • Field Details

  • Constructor Details

    • Exceptions

      private Exceptions()
      Utility class, no instances.
  • Method Details

    • propagate

      public static RuntimeException propagate(Throwable t)
      Convenience method to throw a RuntimeException and Error directly or wrap any other exception type into a RuntimeException.
      Parameters:
      t - the exception to throw directly or wrapped
      Returns:
      because propagate itself throws an exception or error, this is a sort of phantom return value; propagate does not actually return anything
    • throwIfFatal

      public static void throwIfFatal(Throwable t)
      Throws a particular Throwable only if it belongs to a set of "fatal" error varieties. These varieties are as follows: This can be useful if you are writing an operator that calls user-supplied code, and you want to notify subscribers of errors encountered in that code by calling their onError methods, but only if the errors are not so catastrophic that such a call would be futile, in which case you simply want to rethrow the error.
      Parameters:
      t - the Throwable to test and perhaps throw
      See Also:
    • addCause

      public static void addCause(Throwable e, Throwable cause)
      Adds a Throwable to a causality-chain of Throwables, as an additional cause (if it does not already appear in the chain among the causes).
      Parameters:
      e - the Throwable at the head of the causality chain
      cause - the Throwable you want to add as a cause of the chain
    • getFinalCause

      public static Throwable getFinalCause(Throwable e)
      Get the Throwable at the end of the causality-chain for a particular Throwable
      Parameters:
      e - the Throwable whose final cause you are curious about
      Returns:
      the last Throwable in the causality-chain of e (or a "Stack too deep to get final cause" RuntimeException if the chain is too long to traverse)
    • throwIfAny

      public static void throwIfAny(List<? extends Throwable> exceptions)
      Throws a single or multiple exceptions contained in the collection, wrapping it into CompositeException if necessary.
      Parameters:
      exceptions - the collection of exceptions. If null or empty, no exception is thrown. If the collection contains a single exception, that exception is either thrown as-is or wrapped into a CompositeException. Multiple exceptions are wrapped into a CompositeException.
      Since:
      1.1.0
    • throwOrReport

      @Experimental public static void throwOrReport(Throwable t, Observer<?> o, Object value)
      Forwards a fatal exception or reports it along with the value caused it to the given Observer.
      Parameters:
      t - the exception
      o - the observer to report to
      value - the value that caused the exception
      Since:
      (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
    • throwOrReport

      @Experimental public static void throwOrReport(Throwable t, Observer<?> o)
      Forwards a fatal exception or reports it to the given Observer.
      Parameters:
      t - the exception
      o - the observer to report to
      Since:
      (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number)
    • throwOrReport

      @Experimental public static void throwOrReport(Throwable throwable, SingleSubscriber<?> subscriber)
      Forwards a fatal exception or reports it to the given Observer.
      Parameters:
      throwable - the exception.
      subscriber - the subscriber to report to.
      Since:
      (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number).