Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
I'm wanting to handle unchecked exceptions that might happen during runtime to present a better experience to the user. Currently if a component encounters, for example, an ArrayIndexOutOfBoundsException then the entire application is unusable and the user is presented with the stacktrace.
I want to be able to handle this gracefully even if it is nothing more than presenting a "Sorry, we're having technical issues..." page. This post seems fairly old and what I've tried from its suggestions haven't acheived the desired result. I just keep getting the stacktrace.
Running v7.6 on Tomcat, if that helps.
I have just tried the approach of setting the error handler on the UI itself in UI.init() method and it works properly. For example, if I throw a RuntimeException inside of some Button click method, the exception is properly propagated to the error handler, and does not bubble out and present itself with a stacktrace to the user.
You can display the exception in the ErrorHandler itself, e.g. as a notification. The Button will itself not show the exception, nor it will be marked with the red exclamation mark, unless you rethrow the exception in the ErrorHandler.
I have tried this approach in Vaadin 8, but Vaadin 7.x should behave this way as well.
I double checked using both the UI.setErrorHandler and the VaadinSession.getCurrent().setErrorHandler() methods.
If I set a component to throw a RuntimeException on click, then it will present a Notification message as directed by the ErrorHandler set using the above methods. However, if I throw an exception when instantiating a component, then the result is a 500 server error and a ServletException stacktrace. Is this not able to be handled without implementing a catch for every component?
It shouldn't matter what exactly you do in the UI thread, the exception should be propagated properly to the ErrorHandler. Could you please check that the error handler is actually set when the exception occurs? Could you please paste some more code and the exception? Are you instantiating the component in a Table ColumnGenerator, or in a regular button click handler?