From 580559c65d60a29f3628eac616a1b4bbc4da708e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 26 Sep 2011 11:18:09 +0200 Subject: vaadim-app: add uncaught exceptions handler --- .../src/ch/asynk/helloworld/HelloWorldApp.java | 29 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java index c516e55..1185f65 100644 --- a/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java +++ b/vaadin-app/src/ch/asynk/helloworld/HelloWorldApp.java @@ -4,6 +4,7 @@ import java.util.Date; import com.vaadin.Application; import com.vaadin.terminal.UserError; +import com.vaadin.terminal.Terminal; import com.vaadin.data.Property; import com.vaadin.data.Property.ValueChangeEvent; import com.vaadin.data.util.ObjectProperty; @@ -70,6 +71,15 @@ class MainLayout extends VerticalLayout { event.getButton().setComponentError( new UserError("Stop pressing this button !!") ); } })); + /// + Button exceptionButton = new Button("throw an exception"); + addComponent(exceptionButton ); + exceptionButton.addListener( new Button.ClickListener() { + @Override + public void buttonClick(ClickEvent event) { + throw new RuntimeException("Wahou !! : exception"); + } + }); // Button nextButton = new Button("next layout"); nextButton.setDescription("Go to next layout"); @@ -85,14 +95,23 @@ class MainLayout extends VerticalLayout { } public class HelloWorldApp extends Application { + private static final long serialVersionUID = 1L; - private static final long serialVersionUID = 1L; - - @Override - public void init() { + @Override + public void init() { final Window mainWindow = new Window("Hello World Application"); mainWindow.setContent( new MainLayout() ); setMainWindow(mainWindow); setLogoutURL("http://asynk.ch"); - } + } + + @Override + public void terminalError(Terminal.ErrorEvent event) { + // Call the default implementation. + super.terminalError(event); + // Some custom behaviour. + if (getMainWindow() != null) { + getMainWindow().showNotification("An unchecked exception occured!", event.getThrowable().toString(), Window.Notification.TYPE_ERROR_MESSAGE); + } + } } -- cgit v1.1-2-g2b99