最佳答案
我是一个新来的项目 ABc0和一般的响应式编程。
我目前正在编写一段类似的代码:
Mono.just(userId)
.map(repo::findById)
.map(user-> {
if(user == null){
throw new UserNotFoundException();
}
return user;
})
// ... other mappings
This example is probably silly and there are surely better ways of implementing this case, but the point is:
Is it wrong to use a throw new
exception in a map
block or should I replace this with a return Mono.error(new UserNotFoundException())
?
这两种做法有什么实际的区别吗?