Class Exceptions


  • public final class Exceptions
    extends java.lang.Object
    Utility class to help propagate checked exceptions and rethrow exceptions designated as fatal.
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Exceptions()
      Utility class.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static @NonNull java.lang.RuntimeException propagate​(@NonNull java.lang.Throwable t)
      Convenience method to throw a RuntimeException and Error directly or wrap any other exception type into a RuntimeException.
      static void throwIfFatal​(@NonNull java.lang.Throwable t)
      Throws a particular Throwable only if it belongs to a set of "fatal" error varieties.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Exceptions

        private Exceptions()
        Utility class.
    • Method Detail

      • propagate

        @NonNull
        public static @NonNull java.lang.RuntimeException propagate​(@NonNull
                                                                    @NonNull java.lang.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​(@NonNull
                                        @NonNull java.lang.Throwable t)
        Throws a particular Throwable only if it belongs to a set of "fatal" error varieties. These varieties are as follows:
        • VirtualMachineError
        • ThreadDeath
        • LinkageError
        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:
        RxJava: StackOverflowError is swallowed (Issue #748)