笔者最近在使用onErrorStop操作符的时候,发现并没有生效,异常还是被throw出来,并且日志打印了onErrorDroped。仔细看了onErrorStop的java doc发现,每个操作符都有自己的error mode support,即不是每个操作符都能用onErrorStop。
举例doOnNext
/**
* Add behavior (side-effect) triggered when the {@link Flux} emits an item.
* <p>
* <img class="marble" src="doc-files/marbles/doOnNextForFlux.svg" alt="">
* <p>
* The {@link Consumer} is executed first, then the onNext signal is propagated
* downstream.
*
* @param onNext the callback to call on {@link Subscriber#onNext}
*
* <p><strong>Error Mode Support:</strong> This operator supports {@link #onErrorContinue(BiConsumer) resuming on errors}
* (including when fusion is enabled). Exceptions thrown by the consumer are passed to
* the {@link #onErrorContinue(BiConsumer)} error consumer (the value consumer
* is not invoked, as the source element will be part of the sequence). The onNext
* signal is then propagated as normal.
*
* @return an observed {@link Flux}
*/
public final Flux<T> doOnNext(Consumer<? super T> onNext) {
Objects.requireNonNull(onNext, "onNext");
return doOnSignal(this, null, onNext, null, null, null, null, null);
}
中间有一句 * <p><strong>Error Mode Support:</strong> This operator supports {@link #onErrorContinue(BiConsumer) resuming on errors}
意思就是doOnNext只能用onErrorResume