public abstract class Exceptions extends Object
Modifier and Type | Field and Description |
---|---|
static String |
BACKPRESSURE_ERROR_QUEUE_FULL
A common error message used when a reactive streams source doesn't seem to respect
backpressure signals, resulting in an operator's internal queue to be full.
|
static Throwable |
TERMINATED
A singleton instance of a Throwable indicating a terminal state for exceptions,
don't leak this!
|
Modifier and Type | Method and Description |
---|---|
static RuntimeException |
addSuppressed(RuntimeException original,
Throwable suppressed)
Safely suppress a
Throwable on a RuntimeException . |
static Throwable |
addSuppressed(Throwable original,
Throwable suppressed)
|
static <T> boolean |
addThrowable(AtomicReferenceFieldUpdater<T,Throwable> field,
T instance,
Throwable exception)
Update an empty atomic reference with the given exception, or combine further added
exceptions together as suppressed exceptions under a root Throwable with
the
"Multiple exceptions" message, if the atomic reference already holds
one. |
static RuntimeException |
bubble(Throwable t)
Prepare an unchecked
RuntimeException that will bubble upstream if thrown
by an operator. |
static IllegalStateException |
duplicateOnSubscribeException() |
static UnsupportedOperationException |
errorCallbackNotImplemented(Throwable cause)
Return an
UnsupportedOperationException indicating that the error callback
on a subscriber was not implemented, yet an error was propagated. |
static RuntimeException |
failWithCancel()
An exception that is propagated upward and considered as "fatal" as per Reactive
Stream limited list of exceptions allowed to bubble.
|
static IllegalStateException |
failWithOverflow()
Return an
IllegalStateException indicating the receiver is overrun by
more signals than expected in case of a bounded queue, or more generally that data
couldn't be emitted due to a lack of request |
static IllegalStateException |
failWithOverflow(String message)
Return an
IllegalStateException indicating the receiver is overrun by
more signals than expected in case of a bounded queue or more generally that data
couldn't be emitted due to a lack of request |
static RejectedExecutionException |
failWithRejected()
Return a singleton
RejectedExecutionException |
static RejectedExecutionException |
failWithRejected(String message)
Return a new
RejectedExecutionException with given message. |
static RejectedExecutionException |
failWithRejected(Throwable cause)
Return a new
RejectedExecutionException with standard message and cause,
unless the cause is already a RejectedExecutionException created
via failWithRejected(Throwable) (not the singleton-producing variants). |
static RejectedExecutionException |
failWithRejectedNotTimeCapable()
Return a singleton
RejectedExecutionException with a message indicating
the reason is due to the scheduler not being time-capable |
static boolean |
isBubbling(Throwable t)
Check if the given exception is a
bubbled wrapped exception. |
static boolean |
isCancel(Throwable t)
Check if the given error is a
cancel signal . |
static boolean |
isErrorCallbackNotImplemented(Throwable t)
Check if the given error is a
callback not implemented
exception, in which case its cause will be the propagated
error that couldn't be processed. |
static boolean |
isMultiple(Throwable t)
Check a
Throwable to see if it is a composite, as created by multiple(Throwable...) . |
static boolean |
isOverflow(Throwable t)
Check if the given exception represents an
overflow . |
static boolean |
isRetryExhausted(Throwable t)
Check a
Throwable to see if it indicates too many retry attempts have failed. |
static boolean |
isTraceback(Throwable t)
Check a
Throwable to see if it is a traceback, as created by the checkpoint operator or debug utilities. |
static RuntimeException |
multiple(Iterable<Throwable> throwables)
Create a composite exception that wraps the given
Throwable(s) ,
as suppressed exceptions. |
static RuntimeException |
multiple(Throwable... throwables)
Create a composite exception that wraps the given
Throwable(s) ,
as suppressed exceptions. |
static IllegalArgumentException |
nullOrNegativeRequestException(long elements) |
static RuntimeException |
propagate(Throwable t)
Prepare an unchecked
RuntimeException that should be propagated
downstream through Subscriber.onError(Throwable) . |
static RuntimeException |
retryExhausted(String message,
Throwable cause)
Return a new
RuntimeException that represents too many failures on retry. |
static <T> Throwable |
terminate(AtomicReferenceFieldUpdater<T,Throwable> field,
T instance)
Atomic utility to safely mark a volatile throwable reference with a terminal
marker.
|
static void |
throwIfFatal(Throwable t)
Throws a particular
Throwable only if it belongs to a set of "fatal" error
varieties. |
static void |
throwIfJvmFatal(Throwable t)
Throws a particular
Throwable only if it belongs to a set of "fatal" error
varieties native to the JVM. |
static Throwable |
unwrap(Throwable t)
|
static List<Throwable> |
unwrapMultiple(Throwable potentialMultiple)
|
static List<Throwable> |
unwrapMultipleExcludingTracebacks(Throwable potentialMultiple)
|
public static final String BACKPRESSURE_ERROR_QUEUE_FULL
public static final Throwable TERMINATED
public static <T> boolean addThrowable(AtomicReferenceFieldUpdater<T,Throwable> field, T instance, Throwable exception)
"Multiple exceptions"
message, if the atomic reference already holds
one. This is short-circuited if the reference contains TERMINATED
.
Since composite exceptions and traceback exceptions share the same underlying mechanism
of suppressed exceptions, a traceback could be made part of a composite exception.
Use unwrapMultipleExcludingTracebacks(Throwable)
to filter out such elements in
a composite if needed.
T
- the parent instance typefield
- the target field updaterinstance
- the parent instance for the fieldexception
- the Throwable to add.TERMINATED
instance.unwrapMultiple(Throwable)
public static RuntimeException multiple(Throwable... throwables)
Throwable(s)
,
as suppressed exceptions. Instances create by this method can be detected using the
isMultiple(Throwable)
check. The unwrapMultiple(Throwable)
method
will correctly unwrap these to a List
of the suppressed exceptions. Note
that is will also be consistent in producing a List for other types of exceptions
by putting the input inside a single-element List.
Since composite exceptions and traceback exceptions share the same underlying mechanism
of suppressed exceptions, a traceback could be made part of a composite exception.
Use unwrapMultipleExcludingTracebacks(Throwable)
to filter out such elements in
a composite if needed.
throwables
- the exceptions to wrap into a compositeaddThrowable(AtomicReferenceFieldUpdater, Object, Throwable)
public static RuntimeException multiple(Iterable<Throwable> throwables)
Throwable(s)
,
as suppressed exceptions. Instances created by this method can be detected using the
isMultiple(Throwable)
check. The unwrapMultiple(Throwable)
method
will correctly unwrap these to a List
of the suppressed exceptions. Note
that is will also be consistent in producing a List for other types of exceptions
by putting the input inside a single-element List.
Since composite exceptions and traceback exceptions share the same underlying mechanism
of suppressed exceptions, a traceback could be made part of a composite exception.
Use unwrapMultipleExcludingTracebacks(Throwable)
to filter out such elements in
a composite if needed.
throwables
- the exceptions to wrap into a compositeaddThrowable(AtomicReferenceFieldUpdater, Object, Throwable)
public static RuntimeException bubble(Throwable t)
RuntimeException
that will bubble upstream if thrown
by an operator. This method invokes throwIfFatal(Throwable)
.
t
- the root causepublic static IllegalStateException duplicateOnSubscribeException()
IllegalStateException
with a cause message abiding to
reactive stream specification rule 2.12.public static UnsupportedOperationException errorCallbackNotImplemented(Throwable cause)
UnsupportedOperationException
indicating that the error callback
on a subscriber was not implemented, yet an error was propagated.cause
- original error not processed by a receiver.UnsupportedOperationException
indicating the error callback was
not implemented and holding the original propagated error.isErrorCallbackNotImplemented(Throwable)
public static RuntimeException failWithCancel()
RuntimeException
that can be identified via isCancel(java.lang.Throwable)
isCancel(Throwable)
public static IllegalStateException failWithOverflow()
IllegalStateException
indicating the receiver is overrun by
more signals than expected in case of a bounded queue, or more generally that data
couldn't be emitted due to a lack of requestIllegalStateException
isOverflow(Throwable)
public static IllegalStateException failWithOverflow(String message)
IllegalStateException
indicating the receiver is overrun by
more signals than expected in case of a bounded queue or more generally that data
couldn't be emitted due to a lack of requestmessage
- the exception's messageIllegalStateException
isOverflow(Throwable)
public static RejectedExecutionException failWithRejected()
RejectedExecutionException
RejectedExecutionException
public static RejectedExecutionException failWithRejectedNotTimeCapable()
RejectedExecutionException
with a message indicating
the reason is due to the scheduler not being time-capableRejectedExecutionException
public static RejectedExecutionException failWithRejected(Throwable cause)
RejectedExecutionException
with standard message and cause,
unless the cause
is already a RejectedExecutionException
created
via failWithRejected(Throwable)
(not the singleton-producing variants).cause
- the original exception that caused the rejectionRejectedExecutionException
with standard message and causepublic static RejectedExecutionException failWithRejected(String message)
RejectedExecutionException
with given message.message
- the rejection messageRejectedExecutionException
with custom messagepublic static RuntimeException retryExhausted(String message, @Nullable Throwable cause)
RuntimeException
that represents too many failures on retry.
This nature can be detected via isRetryExhausted(Throwable)
.
The cause of the last retry attempt is passed and stored as this exception's cause
.message
- the messagecause
- the cause of the last retry attempt that failed (or null if irrelevant)RuntimeException
representing retry exhaustion due to too many attemptspublic static boolean isOverflow(@Nullable Throwable t)
overflow
.public static boolean isBubbling(@Nullable Throwable t)
bubbled
wrapped exception.public static boolean isCancel(@Nullable Throwable t)
cancel signal
.public static boolean isErrorCallbackNotImplemented(@Nullable Throwable t)
callback not implemented
exception, in which case its cause
will be the propagated
error that couldn't be processed.public static boolean isMultiple(@Nullable Throwable t)
Throwable
to see if it is a composite, as created by multiple(Throwable...)
.t
- the Throwable
to check, null always yields falsemultiple(Throwable...)
, false otherwisepublic static boolean isRetryExhausted(@Nullable Throwable t)
Throwable
to see if it indicates too many retry attempts have failed.
Such an exception can be created via retryExhausted(String, Throwable)
.t
- the Throwable
to check, null always yields falsepublic static boolean isTraceback(@Nullable Throwable t)
Throwable
to see if it is a traceback, as created by the checkpoint operator or debug utilities.t
- the Throwable
to check, null always yields falsepublic static IllegalArgumentException nullOrNegativeRequestException(long elements)
elements
- the invalid requested demandIllegalArgumentException
with a cause message abiding to
reactive stream specification rule 3.9.public static RuntimeException propagate(Throwable t)
RuntimeException
that should be propagated
downstream through Subscriber.onError(Throwable)
.
This method invokes throwIfFatal(Throwable)
.
t
- the root cause@Nullable public static <T> Throwable terminate(AtomicReferenceFieldUpdater<T,Throwable> field, T instance)
T
- the instance typefield
- the atomic containerinstance
- the reference instancepublic static void throwIfFatal(@Nullable Throwable t)
Throwable
only if it belongs to a set of "fatal" error
varieties. These varieties are as follows: BubblingException
(as detectable by isBubbling(Throwable)
)ErrorCallbackNotImplemented
(as detectable by isErrorCallbackNotImplemented(Throwable)
)VirtualMachineError
ThreadDeath
LinkageError
t
- the exception to evaluatepublic static void throwIfJvmFatal(@Nullable Throwable t)
Throwable
only if it belongs to a set of "fatal" error
varieties native to the JVM. These varieties are as follows:
t
- the exception to evaluatepublic static Throwable unwrap(Throwable t)
t
- the exception to unwrappublic static List<Throwable> unwrapMultiple(@Nullable Throwable potentialMultiple)
Throwable
into a List
of Throwables. This is
only done on the condition that said Throwable is a composite exception built by
multiple(Throwable...)
, in which case the list contains the exceptions
wrapped as suppressed exceptions in the composite. In any other case, the list
only contains the input Throwable (or is empty in case of null input).
Since composite exceptions and traceback exceptions share the same underlying mechanism
of suppressed exceptions, a traceback could be made part of a composite exception.
Use unwrapMultipleExcludingTracebacks(Throwable)
to filter out such elements in
a composite if needed.
potentialMultiple
- the Throwable
to unwrap if multipleList
of the exceptions suppressed by the Throwable
if
multiple, or a List containing the Throwable otherwise. Null input results in an
empty List.unwrapMultipleExcludingTracebacks(Throwable)
public static List<Throwable> unwrapMultipleExcludingTracebacks(@Nullable Throwable potentialMultiple)
Throwable
into a List
of Throwables, excluding instances that
are tracebacks
.
This is only done on the condition that said Throwable is a composite exception built by
multiple(Throwable...)
, in which case the returned list contains its suppressed exceptions
minus the tracebacks. In any other case, the list only contains the input Throwable (or is empty in
case of null input).
This is useful because tracebacks are added as suppressed exceptions and thus can appear as components of a composite.
public static final RuntimeException addSuppressed(RuntimeException original, Throwable suppressed)
Throwable
on a RuntimeException
. The returned
RuntimeException
, bearing the suppressed exception, is most often the same
as the original exception unless:
RejectedExecutionException
created
by Reactor: make a copy the RejectedExecutionException
, add the
suppressed exception to it and return that copy.original
- the original RuntimeException
to bear a suppressed exceptionsuppressed
- the Throwable
to suppressRuntimeException
bearing the
suppressed Throwable
public static final Throwable addSuppressed(Throwable original, Throwable suppressed)
Throwable
on an original Throwable
. The returned
Throwable
, bearing the suppressed exception, is most often the same
as the original one unless:
RejectedExecutionException
created
by Reactor: make a copy the RejectedExecutionException
, add the
suppressed exception to it and return that copy.