Class ExceptionHelper
- java.lang.Object
-
- io.reactivex.rxjava3.internal.util.ExceptionHelper
-
public final class ExceptionHelper extends java.lang.Object
Terminal atomics for Throwable containers.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
ExceptionHelper.Termination
-
Field Summary
Fields Modifier and Type Field Description static java.lang.Throwable
TERMINATED
A singleton instance of a Throwable indicating a terminal state for exceptions, don't leak this.
-
Constructor Summary
Constructors Modifier Constructor Description private
ExceptionHelper()
Utility class.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
addThrowable(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> field, java.lang.Throwable exception)
static java.lang.NullPointerException
createNullPointerException(java.lang.String prefix)
Creates a NullPointerException with a composed message vianullWarning(String)
.static java.util.List<java.lang.Throwable>
flatten(java.lang.Throwable t)
Returns a flattened list of Throwables from tree-like CompositeException chain.static <T> T
nullCheck(T value, java.lang.String prefix)
Similar to Objects.requireNonNull but composes the error message vianullWarning(String)
.static java.lang.String
nullWarning(java.lang.String prefix)
Composes a String with a null warning message.static java.lang.Throwable
terminate(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> field)
static <E extends java.lang.Throwable>
java.lang.ExceptionthrowIfThrowable(java.lang.Throwable e)
Workaround for Java 6 not supporting throwing a final Throwable from a catch block.static java.lang.String
timeoutMessage(long timeout, java.util.concurrent.TimeUnit unit)
static java.lang.RuntimeException
wrapOrThrow(java.lang.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.
-
-
-
Method Detail
-
wrapOrThrow
public static java.lang.RuntimeException wrapOrThrow(java.lang.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(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> field, java.lang.Throwable exception)
-
terminate
public static java.lang.Throwable terminate(java.util.concurrent.atomic.AtomicReference<java.lang.Throwable> field)
-
flatten
public static java.util.List<java.lang.Throwable> flatten(java.lang.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 java.lang.Throwable> java.lang.Exception throwIfThrowable(java.lang.Throwable e) throws E extends java.lang.Throwable
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 thrownE extends java.lang.Throwable
-
timeoutMessage
public static java.lang.String timeoutMessage(long timeout, java.util.concurrent.TimeUnit unit)
-
nullWarning
public static java.lang.String nullWarning(java.lang.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 java.lang.NullPointerException createNullPointerException(java.lang.String prefix)
Creates a NullPointerException with a composed message vianullWarning(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, java.lang.String prefix)
Similar to Objects.requireNonNull but composes the error message vianullWarning(String)
.- Type Parameters:
T
- the value type- Parameters:
value
- the value to checkprefix
- the prefix to the error message- Returns:
- the value
- Throws:
java.lang.NullPointerException
- if value is null- Since:
- 3.0.0
-
-