VaadinSession.getCurrent().setErrorHandler(newErrorHandler()) in Vaadin 10

In Vaadin 8 I leveraged VaadinSession.getCurrent().setErrorHandler(newErrorHandler()) to configure ErrorHandler. How to do it in Vaadin 10 ?

Hi.

You can do similar thing, since the VaadinSession api is still there: https://github.com/vaadin/flow/blob/master/flow-server/src/main/java/com/vaadin/flow/server/VaadinSession.java#L370

Here’s an example: https://github.com/vaadin/flow/blob/master/flow-tests/test-root-context/src/main/java/com/vaadin/flow/uitest/ui/ErrorHandlingView.java#L25

Thank you.

I’ve had a look at the ErrorHandlingView mentioned above but I’m not certain how to wire it into my code.


@Route(value = "com.vaadin.flow.uitest.ui.ErrorHandlingView", layout = ViewTestLayout.class)
public class ErrorHandlingView extends AbstractDivView {
    public ErrorHandlingView() {
	
	...
	
	  @Override
    protected void onAttach(AttachEvent attachEvent) {
        super.onAttach(attachEvent);
        attachEvent.getSession().setErrorHandler(e -> {

My reading of the code is that when the ErrorHandlingView is attached to the dom the onAttach method is called which then registers itself as the error handler.

The question is when and where do I attach the errorhandlerview?

For this code to work it would seem that it must be attached to a UI or RouteLayout component.
Interestingly the sample project mentioned above doesn’t actually seem to use this view anywhere in the code so I can’t see how its attached.

It is a route so I thought there may be a piece of code that navigates to it but that doesn’t seem to be the case and really doesn’t make any sense (as it needs to be triggered when an error occurs, but it needs to be attached to catch those errors).

So what am I missing here?