Make exceptions behave like system errors


I would like some exceptions coming from my app to behave like a “native” Vaadin system error. With a system error, the message is shown on the terminal and when the user clicks it, the application is closed/restarted. Vaadin decides that it is not possible (or safe) to continue the application. I would also like to make this decission.

I tried simply throwing a com.vaadin.terminal.SystemError, but it only supports predetermined error conditions and static descriptions for them (“Session expired”, “Out of sync” etc.). I need to display the exception itself, so this will not work.

I can easily use Window.ShowNotification() to make the exception message look the same as a system error. But since a notification does not support any server-side listeners, I cannot dictate that the application must be closed when it is clicked - like a system error does.

I thought of a (rather messy) workaround, but perhaps you Vaadin guys can think of something more elegant. The workaround is this: put a href inside the notification message pointing to the main application url appended with “?restartApplication”. When the user clicks on it (like I expect from a well-behaved user) the app is closed nicely. But when the user is not well-behaved (unlikely, I know), he/she will click somewhere else in the notification area, and the application will still be active. To get around this, I could set the session expiration timeout to 1 second, just before issuing the notification. Together with the “redirect to logout url on session expire” facility, this will trigger the application close as soon as the browser tries to communicate with the server - the next best thing.

But as I said, this workaround is quite hackish. Is there an easier way to accomplish this?