在反应器 3 中抛出多个错误
throw multiple errors in reactor 3
Flux.create(sink -> {
sink.error(new IOException());
sink.error(new IOException());
}).subscribe(System.out::println, System.out::println, System.out::println);
我认为(错误地)在第一个错误之后,通量将被处理并且不再监听任何信号,但上面的代码产生了一个异常:
java.io.IOException
Exception in thread "main" reactor.core.Exceptions$BubblingException: java.io.IOException
at reactor.core.Exceptions.bubble(Exceptions.java:154)
at reactor.core.publisher.Operators.onErrorDropped(Operators.java:256)
at reactor.core.publisher.FluxCreate$SerializedSink.error(FluxCreate.java:172)
at main.App.lambda$f1[=11=](App.java:30)
at reactor.core.publisher.FluxCreate.subscribe(FluxCreate.java:92)
at reactor.core.publisher.Flux.subscribe(Flux.java:6447)
at reactor.core.publisher.Flux.subscribeWith(Flux.java:6614)
at reactor.core.publisher.Flux.subscribe(Flux.java:6440)
at reactor.core.publisher.Flux.subscribe(Flux.java:6404)
at main.App.f1(App.java:31)
at main.App.main(App.java:23)
Caused by: java.io.IOException
... 8 more
为什么我得到这个异常?
根据反应流,发出 onError()
两次信号是非法的,当 create
运算符收到第二个异常时,它会丢弃它。有一个钩子可以用来捕获这种情况并用它做一些有意义的事情,但在你的情况下,默认实现会启动,它只是包装无关的异常并抛出它,或者 "bubble" 它,给来电者。
Flux.create(sink -> {
sink.error(new IOException());
sink.error(new IOException());
}).subscribe(System.out::println, System.out::println, System.out::println);
我认为(错误地)在第一个错误之后,通量将被处理并且不再监听任何信号,但上面的代码产生了一个异常:
java.io.IOException
Exception in thread "main" reactor.core.Exceptions$BubblingException: java.io.IOException
at reactor.core.Exceptions.bubble(Exceptions.java:154)
at reactor.core.publisher.Operators.onErrorDropped(Operators.java:256)
at reactor.core.publisher.FluxCreate$SerializedSink.error(FluxCreate.java:172)
at main.App.lambda$f1[=11=](App.java:30)
at reactor.core.publisher.FluxCreate.subscribe(FluxCreate.java:92)
at reactor.core.publisher.Flux.subscribe(Flux.java:6447)
at reactor.core.publisher.Flux.subscribeWith(Flux.java:6614)
at reactor.core.publisher.Flux.subscribe(Flux.java:6440)
at reactor.core.publisher.Flux.subscribe(Flux.java:6404)
at main.App.f1(App.java:31)
at main.App.main(App.java:23)
Caused by: java.io.IOException
... 8 more
为什么我得到这个异常?
根据反应流,发出 onError()
两次信号是非法的,当 create
运算符收到第二个异常时,它会丢弃它。有一个钩子可以用来捕获这种情况并用它做一些有意义的事情,但在你的情况下,默认实现会启动,它只是包装无关的异常并抛出它,或者 "bubble" 它,给来电者。