I use Vaadin framework to create my web application GUI.
I have a Vaadin button and its click listener code may throw an application custom exception. In other points of application code, this exception is thrown all the way back to my custom window class, where it’s centrally handled. I’d like to do something similar here: throw this exception in the clickListener code, so I could catch it in my custom terminal error handler in the window class. As the click listener class does not throw any exception, I’m unable to throw the exception there and I think I’ll be obliged to handle the exception locally. As I don’t want to handle the exception at the button click listener level, I think I’ll forward it to my custom window class. Something like this:
Button btnNew = new Button("New", new Button.ClickListener() {
public void buttonClick(ClickEvent event) {
try {
doThingThatThrowsException();
} catch (Exception exc) {
window.handleCustomException()
}
}
});
Is this the usual way of centralizing handling of a custom exception using Vaadin?
I can’t answer as to whether it’s the usual way of handling the exception, but we do something very similar.
Depending on how many listeners or how often you have to do this, you could also create abstract listeners that do that delegation for you.
e.g.