我正在使用可流动迭代器,并处理来自可迭代器的每个项目的请求。如果抛出任何异常,如何找出发生异常的输入。
例如:
Flowable.fromIterable(userList)
.flatMap(d -> Flowable.fromCallable(() -> getClaimStatus(d))
).map(d -> updateClaimStatus(d))
.subscribe(d -> System.out.println("Processed"),
err -> System.err.println(err.getMessage()));我只想打印出发生错误的用户。
发布于 2018-06-21 21:19:06
您可以尝试在fromCallable/map中捕获并抛出您选择的包装器异常:
Flowable.fromIterable(userList)
.flatMap(d -> Flowable.fromCallable(() -> {
try {
return getClaimStatus(d);
} catch (Exception ex) {
throw new Exception("User: " + d, ex);
}
}))
.map(d -> {
try {
return updateClaimStatus(d);
} catch (Exception ex) {
throw new Exception("User: " + d, ex);
}
})
.subscribe(
d -> System.out.println("Processed"),
err -> System.err.println(err.getMessage())
);https://stackoverflow.com/questions/50969160
复制相似问题