public abstract class Exceptions
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static class |
Exceptions.SourceException
A
Throwable that wraps the actual cause delivered via
Subscriber.onError(Throwable) in case of
Publisher s that themselves emit items of type
Publisher . |
Modifier and Type | Field and Description |
---|---|
static java.util.function.Consumer<? super java.lang.AutoCloseable> |
AUTO_CLOSE
A general-purpose
Consumer that closes AutoCloseable resource. |
static java.lang.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 java.lang.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 java.lang.RuntimeException |
addSuppressed(java.lang.RuntimeException original,
java.lang.Throwable suppressed)
Safely suppress a
Throwable on a RuntimeException . |
static java.lang.Throwable |
addSuppressed(java.lang.Throwable original,
java.lang.Throwable suppressed)
Safely suppress a
Throwable on an original Throwable . |
static <T> boolean |
addThrowable(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,java.lang.Throwable> field,
T instance,
java.lang.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 java.lang.RuntimeException |
bubble(java.lang.Throwable t)
Prepare an unchecked
RuntimeException that will bubble upstream if thrown
by an operator. |
static java.lang.IllegalStateException |
duplicateOnSubscribeException() |
static java.lang.UnsupportedOperationException |
errorCallbackNotImplemented(java.lang.Throwable cause)
Return an
UnsupportedOperationException indicating that the error callback
on a subscriber was not implemented, yet an error was propagated. |
static java.lang.RuntimeException |
failWithCancel()
An exception that is propagated upward and considered as "fatal" as per Reactive
Stream limited list of exceptions allowed to bubble.
|
static java.lang.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 java.lang.IllegalStateException |
failWithOverflow(java.lang.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 java.util.concurrent.RejectedExecutionException |
failWithRejected()
Return a singleton
RejectedExecutionException |
static java.util.concurrent.RejectedExecutionException |
failWithRejected(java.lang.String message)
Return a new
RejectedExecutionException with given message. |
static java.util.concurrent.RejectedExecutionException |
failWithRejected(java.lang.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 java.util.concurrent.RejectedExecutionException |
failWithRejectedNotTimeCapable()
Return a singleton
RejectedExecutionException with a message indicating
the reason is due to the scheduler not being time-capable |
static boolean |
isBubbling(java.lang.Throwable t)
Check if the given exception is a
bubbled wrapped exception. |
static boolean |
isCancel(java.lang.Throwable t)
Check if the given error is a
cancel signal . |
static boolean |
isErrorCallbackNotImplemented(java.lang.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 |
isFatal(java.lang.Throwable t)
Check if a
Throwable is considered by Reactor as Fatal and would be thrown by
throwIfFatal(Throwable) . |
static boolean |
isJvmFatal(java.lang.Throwable t)
Check if a
Throwable is considered by Reactor as Jvm Fatal and would be thrown
by both throwIfFatal(Throwable) and throwIfJvmFatal(Throwable) . |
static boolean |
isMultiple(java.lang.Throwable t)
Check a
Throwable to see if it is a composite, as created by multiple(Throwable...) . |
static boolean |
isOverflow(java.lang.Throwable t)
Check if the given exception represents an
overflow . |
static boolean |
isRetryExhausted(java.lang.Throwable t)
Check a
Throwable to see if it indicates too many retry attempts have failed. |
static boolean |
isTraceback(java.lang.Throwable t)
Check a
Throwable to see if it is a traceback, as created by the checkpoint operator or debug utilities. |
static java.lang.RuntimeException |
multiple(java.lang.Iterable<java.lang.Throwable> throwables)
Create a composite exception that wraps the given
Throwable(s) ,
as suppressed exceptions. |
static java.lang.RuntimeException |
multiple(java.lang.Throwable... throwables)
Create a composite exception that wraps the given
Throwable(s) ,
as suppressed exceptions. |
static java.lang.IllegalArgumentException |
nullOrNegativeRequestException(long elements) |
static java.lang.RuntimeException |
propagate(java.lang.Throwable t)
Prepare an unchecked
RuntimeException that should be propagated
downstream through Subscriber.onError(Throwable) . |
static java.lang.RuntimeException |
retryExhausted(java.lang.String message,
java.lang.Throwable cause)
Return a new
RuntimeException that represents too many failures on retry. |
static <T> java.lang.Throwable |
terminate(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,java.lang.Throwable> field,
T instance)
Atomic utility to safely mark a volatile throwable reference with a terminal
marker.
|
static void |
throwIfFatal(java.lang.Throwable t)
Throws a particular
Throwable only if it belongs to a set of "fatal" error
varieties. |
static void |
throwIfJvmFatal(java.lang.Throwable t)
Throws a particular
Throwable only if it belongs to a set of "fatal" error
varieties native to the JVM. |
static java.lang.Throwable |
unwrap(java.lang.Throwable t)
|
static java.util.List<java.lang.Throwable> |
unwrapMultiple(java.lang.Throwable potentialMultiple)
Attempt to unwrap a
Throwable into a List of Throwables. |
static java.util.List<java.lang.Throwable> |
unwrapMultipleExcludingTracebacks(java.lang.Throwable potentialMultiple)
|
static java.lang.Throwable |
wrapSource(java.lang.Throwable throwable)
Wrap a
Throwable delivered via Subscriber.onError(Throwable)
from an upstream Publisher that itself
emits Publisher s to distinguish the error signal from
the inner sequence's processing errors. |
public static final java.lang.String BACKPRESSURE_ERROR_QUEUE_FULL
public static final java.lang.Throwable TERMINATED
public static final java.util.function.Consumer<? super java.lang.AutoCloseable> AUTO_CLOSE
Consumer
that closes AutoCloseable
resource.
If exception is thrown during closing the resource, it will be propagated by propagate(Throwable)
.public static <T> boolean addThrowable(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,java.lang.Throwable> field, T instance, java.lang.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 java.lang.Throwable wrapSource(java.lang.Throwable throwable)
Throwable
delivered via Subscriber.onError(Throwable)
from an upstream Publisher
that itself
emits Publisher
s to distinguish the error signal from
the inner sequence's processing errors.throwable
- the source sequence error
signalExceptions.SourceException
public static java.lang.RuntimeException multiple(java.lang.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 java.lang.RuntimeException multiple(java.lang.Iterable<java.lang.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 java.lang.RuntimeException bubble(java.lang.Throwable t)
RuntimeException
that will bubble upstream if thrown
by an operator. This method invokes throwIfFatal(Throwable)
.
t
- the root causepublic static java.lang.IllegalStateException duplicateOnSubscribeException()
IllegalStateException
with a cause message abiding to
reactive stream specification rule 2.12.public static java.lang.UnsupportedOperationException errorCallbackNotImplemented(java.lang.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 java.lang.RuntimeException failWithCancel()
RuntimeException
that can be identified via isCancel(java.lang.Throwable)
isCancel(Throwable)
public static java.lang.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 java.lang.IllegalStateException failWithOverflow(java.lang.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 java.util.concurrent.RejectedExecutionException failWithRejected()
RejectedExecutionException
RejectedExecutionException
public static java.util.concurrent.RejectedExecutionException failWithRejectedNotTimeCapable()
RejectedExecutionException
with a message indicating
the reason is due to the scheduler not being time-capableRejectedExecutionException
public static java.util.concurrent.RejectedExecutionException failWithRejected(java.lang.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 java.util.concurrent.RejectedExecutionException failWithRejected(java.lang.String message)
RejectedExecutionException
with given message.message
- the rejection messageRejectedExecutionException
with custom messagepublic static java.lang.RuntimeException retryExhausted(java.lang.String message, @Nullable java.lang.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 java.lang.Throwable t)
overflow
.t
- the Throwable
error to checkThrowable
represents an overflow.public static boolean isBubbling(@Nullable java.lang.Throwable t)
bubbled
wrapped exception.t
- the Throwable
error to checkThrowable
is a bubbled wrapped exception.public static boolean isCancel(@Nullable java.lang.Throwable t)
cancel signal
.t
- the Throwable
error to checkThrowable
is a cancellation token.public static boolean isErrorCallbackNotImplemented(@Nullable java.lang.Throwable t)
callback not implemented
exception, in which case its cause
will be the propagated
error that couldn't be processed.t
- the Throwable
error to checkThrowable
is a callback not implemented exception.public static boolean isMultiple(@Nullable java.lang.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 java.lang.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 java.lang.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 java.lang.IllegalArgumentException nullOrNegativeRequestException(long elements)
elements
- the invalid requested demandIllegalArgumentException
with a cause message abiding to
reactive stream specification rule 3.9.public static java.lang.RuntimeException propagate(java.lang.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> java.lang.Throwable terminate(java.util.concurrent.atomic.AtomicReferenceFieldUpdater<T,java.lang.Throwable> field, T instance)
T
- the instance typefield
- the atomic containerinstance
- the reference instancepublic static boolean isJvmFatal(@Nullable java.lang.Throwable t)
Throwable
is considered by Reactor as Jvm Fatal and would be thrown
by both throwIfFatal(Throwable)
and throwIfJvmFatal(Throwable)
.
This is a subset of isFatal(Throwable)
, namely:
VirtualMachineError
ThreadDeath
LinkageError
Unless wrapped explicitly, such exceptions would always be thrown by operators instead of propagation through onError, potentially interrupting progress of Flux/Mono sequences. When they occur, the JVM itself is assumed to be in an unrecoverable state, and so is Reactor.
t
- the Throwable
to checkthrowIfFatal(Throwable)
,
throwIfJvmFatal(Throwable)
,
isFatal(Throwable)
public static boolean isFatal(@Nullable java.lang.Throwable t)
Throwable
is considered by Reactor as Fatal and would be thrown by
throwIfFatal(Throwable)
.
BubblingException
(as detectable by isBubbling(Throwable)
)ErrorCallbackNotImplemented
(as detectable by isErrorCallbackNotImplemented(Throwable)
)Jvm Fatal exceptions
VirtualMachineError
ThreadDeath
LinkageError
Unless wrapped explicitly, such exceptions would always be thrown by operators instead of propagation through onError, potentially interrupting progress of Flux/Mono sequences. When they occur, the assumption is that Reactor is in an unrecoverable state (notably because the JVM itself might be in an unrecoverable state).
t
- the Throwable
to checkthrowIfFatal(Throwable)
,
isJvmFatal(Throwable)
public static void throwIfFatal(@Nullable java.lang.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 java.lang.Throwable t)
Throwable
only if it belongs to a set of "fatal" error
varieties native to the JVM. These varieties are as follows:
VirtualMachineError
ThreadDeath
LinkageError
t
- the exception to evaluatepublic static java.lang.Throwable unwrap(java.lang.Throwable t)
t
- the exception to unwrappublic static java.util.List<java.lang.Throwable> unwrapMultiple(@Nullable java.lang.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 java.util.List<java.lang.Throwable> unwrapMultipleExcludingTracebacks(@Nullable java.lang.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.
potentialMultiple
- the Throwable
to unwrap if multipleList
of the exceptions suppressed by the Throwable
minus the
tracebacks if multiple, or a List containing the Throwable otherwise. Null input results in an
empty List.public static final java.lang.RuntimeException addSuppressed(java.lang.RuntimeException original, java.lang.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 java.lang.Throwable addSuppressed(java.lang.Throwable original, java.lang.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.original
- the original Throwable
to bear a suppressed exceptionsuppressed
- the Throwable
to suppressThrowable
bearing the
suppressed Throwable