Package rx.exceptions
Class Exceptions
- java.lang.Object
-
- rx.exceptions.Exceptions
-
public final class Exceptions extends java.lang.Object
Utility class with methods to wrap checked exceptions and manage fatal and regular exception delivery.
-
-
Field Summary
Fields Modifier and Type Field Description private static int
MAX_DEPTH
-
Constructor Summary
Constructors Modifier Constructor Description private
Exceptions()
Utility class, no instances.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addCause(java.lang.Throwable e, java.lang.Throwable cause)
Adds aThrowable
to a causality-chain of Throwables, as an additional cause (if it does not already appear in the chain among the causes).static java.lang.Throwable
getFinalCause(java.lang.Throwable e)
Get theThrowable
at the end of the causality-chain for a particularThrowable
static java.lang.RuntimeException
propagate(java.lang.Throwable t)
Convenience method to throw aRuntimeException
andError
directly or wrap any other exception type into aRuntimeException
.static void
throwIfAny(java.util.List<? extends java.lang.Throwable> exceptions)
Throws a single or multiple exceptions contained in the collection, wrapping it intoCompositeException
if necessary.static void
throwIfFatal(java.lang.Throwable t)
Throws a particularThrowable
only if it belongs to a set of "fatal" error varieties.static void
throwOrReport(java.lang.Throwable t, Observer<?> o)
Forwards a fatal exception or reports it to the given Observer.static void
throwOrReport(java.lang.Throwable t, Observer<?> o, java.lang.Object value)
Forwards a fatal exception or reports it along with the value caused it to the given Observer.static void
throwOrReport(java.lang.Throwable throwable, SingleSubscriber<?> subscriber)
Forwards a fatal exception or reports it to the given Observer.
-
-
-
Field Detail
-
MAX_DEPTH
private static final int MAX_DEPTH
- See Also:
- Constant Field Values
-
-
Method Detail
-
propagate
public static java.lang.RuntimeException propagate(java.lang.Throwable t)
Convenience method to throw aRuntimeException
andError
directly or wrap any other exception type into aRuntimeException
.- 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(java.lang.Throwable t)
Throws a particularThrowable
only if it belongs to a set of "fatal" error varieties. These varieties are as follows:OnErrorNotImplementedException
OnErrorFailedException
OnCompletedFailedException
StackOverflowError
VirtualMachineError
ThreadDeath
LinkageError
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
- theThrowable
to test and perhaps throw- See Also:
- RxJava: StackOverflowError is swallowed (Issue #748)
-
addCause
public static void addCause(java.lang.Throwable e, java.lang.Throwable cause)
Adds aThrowable
to a causality-chain of Throwables, as an additional cause (if it does not already appear in the chain among the causes).- Parameters:
e
- theThrowable
at the head of the causality chaincause
- theThrowable
you want to add as a cause of the chain
-
getFinalCause
public static java.lang.Throwable getFinalCause(java.lang.Throwable e)
Get theThrowable
at the end of the causality-chain for a particularThrowable
- Parameters:
e
- theThrowable
whose final cause you are curious about- Returns:
- the last
Throwable
in the causality-chain ofe
(or a "Stack too deep to get final cause"RuntimeException
if the chain is too long to traverse)
-
throwIfAny
public static void throwIfAny(java.util.List<? extends java.lang.Throwable> exceptions)
Throws a single or multiple exceptions contained in the collection, wrapping it intoCompositeException
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(java.lang.Throwable t, Observer<?> o, java.lang.Object value)
Forwards a fatal exception or reports it along with the value caused it to the given Observer.- Parameters:
t
- the exceptiono
- the observer to report tovalue
- 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(java.lang.Throwable t, Observer<?> o)
Forwards a fatal exception or reports it to the given Observer.- Parameters:
t
- the exceptiono
- 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(java.lang.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).
-
-