rxjava reactor,用于传播异常的实用程序

时间:2017-06-29 12:48:02

标签: exception rx-java project-reactor propagation

我正在尝试编写一个实用程序,它以重新激活的方式自动传播已检查的异常,而无需在我的运算符中编写带有静态块的样板代码:

    public class ReactRethrow {
        public static <T, R> Function<T, R> rethrow(Function<T, R> catchedFunc) {

            return t -> {
            try {
                return catchedFunc.apply(t);
            } catch (Exception e) {
                throw Exceptions.propagate(e);
            }
        };
    }
}

但它仍抱怨IOException:

Flux.fromArray(resources).map(ReactRethrow.rethrow(resource -> Paths.get(resource.getURI())))

任何想法?

1 个答案:

答案 0 :(得分:1)

有一个原因我不清楚你理解你必须把一个抛出异常的函数作为参数,因此声明一个特定的functionalInterface:

<body onload="createPlayer(); check()">
  <div id="demo"></div>
  <button onclick="prevItem()" id="prev_btn"><img src="assets/next-button.png" alt=prev>
        <br>
</button>&nbsp;<button onclick="nextItem()" id=next_btn><img src="assets/next-button.png" alt=next></button>
  <div id="number"></div>
</body>

从这里https://leoniedermeier.github.io/docs/java/java8/streams_with_checked_exceptions.html