在 Java Reactor 中阻塞调用后如何重新抛出错误?

How to re-throw error after blocking call in Java Reactor?

当我在 Java Reactor 中调用 .block() 时,如果出现错误,它会抛出 ReactiveException。我需要获取包装到 ReactiveException 中的源异常并重新抛出它。

此代码有效,但有没有更好的方法来实现目标?

try {
    return myService.getObject(.....).block();
} catch (Exception e) {
    throw e.getCause() != null ? e.getCause() : e;
}

使用Exceptions.unwrap(e)

例如:


import reactor.core.Exceptions;

...

try {
    return myService.getObject(.....).block();
} catch (Exception e) {
    throw Exceptions.unwrap(e);
}