I have some methods in my reactive chain that can throw exception. If an exception happens - I don't want to continue executing the chain, and I want to log - what exact action threw the exception.
I wrote a code, that looks something like this:
Mono<Void> mono = Mono.just(10)
.map(a -> action1(a))
.doOnError((t) -> System.out.println("action 1 threw an exception"))
.onErrorStop()
.map(a -> action2(a))
.doOnError((t) -> System.out.println("action 2 threw an exception"))
.then();
mono.subscribe();
but when action1
throws an exception - I get the following output:
action 1 threw an exception
action 2 threw an exception
what's not what I expected