diff options
author | Artur Signell <artur.signell@itmill.com> | 2008-08-22 07:25:23 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2008-08-22 07:25:23 +0000 |
commit | 92af8c26fc058869ba902e65adab799fb3370a7b (patch) | |
tree | d37ab056e073d67d12e85f83e63a47066a76a61f /src/com/itmill/toolkit/Application.java | |
parent | 7e80369a74187c96ace452a1deaeceffd0251eae (diff) | |
download | vaadin-framework-92af8c26fc058869ba902e65adab799fb3370a7b.tar.gz vaadin-framework-92af8c26fc058869ba902e65adab799fb3370a7b.zip |
Fixes for #2002 and #1642 - improved exception handling in CommunicationManager
svn changeset:5242/svn branch:trunk
Diffstat (limited to 'src/com/itmill/toolkit/Application.java')
-rw-r--r-- | src/com/itmill/toolkit/Application.java | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/src/com/itmill/toolkit/Application.java b/src/com/itmill/toolkit/Application.java index 2c072284ff..1196891014 100644 --- a/src/com/itmill/toolkit/Application.java +++ b/src/com/itmill/toolkit/Application.java @@ -5,6 +5,7 @@ package com.itmill.toolkit; import java.net.MalformedURLException; +import java.net.SocketException; import java.net.URL; import java.util.Collection; import java.util.Collections; @@ -27,6 +28,7 @@ import com.itmill.toolkit.terminal.SystemError; import com.itmill.toolkit.terminal.Terminal; import com.itmill.toolkit.terminal.URIHandler; import com.itmill.toolkit.terminal.VariableOwner; +import com.itmill.toolkit.terminal.gwt.server.ChangeVariablesErrorEvent; import com.itmill.toolkit.ui.AbstractComponent; import com.itmill.toolkit.ui.Component; import com.itmill.toolkit.ui.Window; @@ -178,6 +180,12 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener private Focusable pendingFocus; /** + * Application wide error handler which is used by default if an error is + * left unhandled. + */ + private Terminal.ErrorListener errorHandler = this; + + /** * <p> * Gets a window by name. Returns <code>null</code> if the application is * not running or it does not contain a window corresponding to the name. @@ -1074,8 +1082,17 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener * @see com.itmill.toolkit.terminal.Terminal.ErrorListener#terminalError(com.itmill.toolkit.terminal.Terminal.ErrorEvent) */ public void terminalError(Terminal.ErrorEvent event) { - // throw it to standard error stream too - event.getThrowable().printStackTrace(); + Throwable t = event.getThrowable(); + if (t instanceof SocketException) { + // Most likely client browser closed socket + System.err + .println("Warning: SocketException in CommunicationManager." + + " Most likely client (browser) closed socket."); + + } else { + // throw it to standard error stream too + t.printStackTrace(); + } // Finds the original source of the error/exception Object owner = null; @@ -1085,6 +1102,8 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener owner = ((URIHandler.ErrorEvent) event).getURIHandler(); } else if (event instanceof ParameterHandler.ErrorEvent) { owner = ((ParameterHandler.ErrorEvent) event).getParameterHandler(); + } else if (event instanceof ChangeVariablesErrorEvent) { + owner = ((ChangeVariablesErrorEvent) event).getComponent(); } // Shows the error in AbstractComponent @@ -1146,6 +1165,28 @@ public abstract class Application implements URIHandler, Terminal.ErrorListener } /** + * Gets the application error handler. + * + * The default error handler is the application itself. + * + * @return Application error handler + */ + public Terminal.ErrorListener getErrorHandler() { + return errorHandler; + } + + /** + * Sets the application error handler. + * + * The default error handler is the application itself. + * + * @param errorHandler + */ + public void setErrorHandler(Terminal.ErrorListener errorHandler) { + this.errorHandler = errorHandler; + } + + /** * Experimental API, not finalized. Contains the system messages used to * notify the user about various critical situations that can occur. * <p> |