我试图在每个失败阶段记录,据我所知,我需要将 try 和 log 嵌套在平面图中。
Try.of(() -> true).
onFailure(h -> System.out.println("first onFailure")).
flatMap(i -> Try.of(() -> { throw new RuntimeException(); }).
onFailure(j -> System.out.println("second onFailure"))).
flatMap(k -> Try.of(() -> true).
onFailure(l -> System.out.println("third onFailure")));
有没有比上述更简单的方法?库中是否有可用于替换嵌套Try.of()
s 的函数?