运行代码时,输出如下:
(a)测试(a = 100)
(b)错误此处-java.lang.NullPointerException
在当前输出中,每当第二项引发异常时,就停止可流动的处理。但是我想像这样处理第三个对象
(a)测试(a = 100)
(b)此处错误{} java.lang.NullPointerException
(c)测试(a = 200)
public class Test {
Integer a;
public Integer getA() {
return a * 10;
}
public static void main(String[] args) {
Test test = new Test(10);
Test test2 = new Test(null); //this object throws exception when it enters flowable
Test test3 = new Test(20);
List<Test> strings = Arrays.asList(test, test2, test3);
Flowable.fromCallable(() -> strings)
.flatMap(s -> Flowable.fromIterable(s)
.flatMap(a -> {
System.out.println(a);
return Flowable.just(a);
})
.onErrorResumeNext(r -> {
System.out.println("error here " + r);
return Flowable.empty();
})
)
.onErrorResumeNext(s -> {
return Flowable.empty();
})
.subscribe();
}`
}
我尝试了上述方法,但不起作用。