Giriş
Flux kapatılır
Şöyle yaparız
Flux<String> stringFlux = Flux.just("Hello", "World", "from", "IntelliJ IDEA").map(s -> {if (s.equals("World")) throw new RuntimeException("An error occurred");else return s.toUpperCase();});stringFlux.onErrorReturn("Error occurred in the stream.").subscribe(System.out::println);
Çıktı şöyle
HELLO Error occurred in the stream.
Örnek
Şöyle yaparız
Flux<Integer> numbers = Flux.just(1, 2, 3, 4, 5)
  .concatWith(Flux.error(new RuntimeException("Oops! An error occurred.")))
  .map(number -> 10 / (number - 3)) // This will cause an ArithmeticException
  .doOnError(throwable -> System.err.println("Error occurred: " + throwable.getMessage()))
  .onErrorReturn(-1); // Provide a fallback value in case of an error
numbers.subscribe(
  value -> System.out.println("Received: " + value),
  error -> System.err.println("Subscriber error: " + error.getMessage())
); 
Hiç yorum yok:
Yorum Gönder