public final class Exceptions extends Object
Modifier and Type | Method and Description |
---|---|
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). |
static Throwable |
getFinalCause(Throwable e)
Get the
Throwable at the end of the causality-chain for a particular Throwable |
static RuntimeException |
propagate(Throwable t)
Convenience method to throw a
RuntimeException and Error directly
or wrap any other exception type into a RuntimeException . |
static void |
throwIfAny(List<? extends Throwable> exceptions)
Throws a single or multiple exceptions contained in the collection, wrapping it into
CompositeException if necessary. |
static void |
throwIfFatal(Throwable t)
Throws a particular
Throwable only if it belongs to a set of "fatal" error varieties. |
static void |
throwOrReport(Throwable t,
Observer<?> o)
Forwards a fatal exception or reports it to the given Observer.
|
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.
|
static void |
throwOrReport(Throwable throwable,
SingleSubscriber<?> subscriber)
Forwards a fatal exception or reports it to the given Observer.
|
public static RuntimeException propagate(Throwable t)
RuntimeException
and Error
directly
or wrap any other exception type into a RuntimeException
.t
- the exception to throw directly or wrappedpropagate
itself throws an exception or error, this is a sort of phantom return
value; propagate
does not actually return anythingpublic static void throwIfFatal(Throwable t)
Throwable
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.t
- the Throwable
to test and perhaps throwpublic static void addCause(Throwable e, Throwable cause)
Throwable
to a causality-chain of Throwables, as an additional cause (if it does not
already appear in the chain among the causes).e
- the Throwable
at the head of the causality chaincause
- the Throwable
you want to add as a cause of the chainpublic static Throwable getFinalCause(Throwable e)
Throwable
at the end of the causality-chain for a particular Throwable
e
- the Throwable
whose final cause you are curious aboutThrowable
in the causality-chain of e
(or a "Stack too deep to get
final cause" RuntimeException
if the chain is too long to traverse)public static void throwIfAny(List<? extends Throwable> exceptions)
CompositeException
if necessary.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.@Experimental public static void throwOrReport(Throwable t, Observer<?> o, Object value)
t
- the exceptiono
- the observer to report tovalue
- the value that caused the exception@Experimental public static void throwOrReport(Throwable t, Observer<?> o)
t
- the exceptiono
- the observer to report to@Experimental public static void throwOrReport(Throwable throwable, SingleSubscriber<?> subscriber)
throwable
- the exception.subscriber
- the subscriber to report to.Copyright © 2023. All rights reserved.