I have some basic ExceptionHandler
view:
@ParentLayout(MainLayout.class)
@AnonymousAllowed
public class ExceptionHandler extends VerticalLayout implements HasErrorParameter<Exception> {
static final Logger logger = LoggerFactory.getLogger(ExceptionHandler.class);
@Override
public int setErrorParameter(BeforeEnterEvent event, ErrorParameter<Exception> parameter) {
logger.error("Error", parameter.getException());
Label label = new Label(parameter.getException().getMessage());
add(label);
return HttpServletResponse.SC_NOT_FOUND;
}
}
which works fine when error occurs in synchronous calls.
But when I use @Async
feature, like for example:
ListenableFuture<DecisionMatrixPage> listenableFuture = container.queryDataAsync();
var ui = UI.getCurrent();
listenableFuture.addCallback(page -> {
ui.access(() -> {
//do something
});
}, err -> {
logger.error("Error", err);
throw new AsyncException("Async error", err);
});
I may only log the error but unfortunately rethrowing of AsyncException
is not catched by ExceptionHandler
view. How to properly re-throw exception to be catched by ExceptionHandler
?