> Markdown version of [Custom Error Handling](https://vaadin.com/docs/v23/advanced/custom-error-handler). Section index: [llms.txt](https://vaadin.com/docs/v23/advanced/llms.txt)

# Custom Error Handling

You can customize the error views related to navigation between different routes as described in the [Router Exception Handling](https://vaadin.com/docs/v23/routing/exceptions.md) article.

For other unhandled runtime exceptions, an `ErrorHandler` class can be used to let users know that something went wrong. To do so, first create your custom `ErrorHandler` class, then use that class to override the default error handler.

For example, the following `CustomErrorHandler` class logs the error and displays a friendly notification to the user.

```java
public class CustomErrorHandler implements ErrorHandler {

    private static final Logger logger = LoggerFactory.getLogger(CustomErrorHandler.class);

    @Override
    public void error(ErrorEvent errorEvent) {
        logger.error("Something wrong happened", errorEvent.getThrowable());
        if(UI.getCurrent() != null) {
            UI.getCurrent().access(() -> {
                Notification.show("An internal error has occurred." +
                        "Contact support for assistance.");
            });
        }
    }
}
```

Then assign the custom error handler to the current user session:

```java
VaadinSession.getCurrent().setErrorHandler(new CustomErrorHandler());
```

To apply the custom error handler to all user sessions, you can use a `SessionInitListener`, which receives an event each time a new `VaadinSession` is initialized. See the [Session and UI Listeners](https://vaadin.com/docs/v23/advanced/session-and-ui-init-listener.md) article to learn how to create a `SessionInitListener`.

`98746DB3-C9AC-42AD-A43D-D79F09B2155E`
