From 8ba83959c94e2e122a8113bed3275ff8679da03b Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Sat, 18 Feb 2012 16:41:15 +0000 Subject: [PATCH] Exceptions happening in functions were uncaugh when they were run in asynchronous blocks. Adding fe() functions and calling then from async methods like binding or queuing, we can notice developers about errors if they set the GWT UncaughtExceptionHandler --- .../com/google/gwt/query/client/Function.java | 73 ++++++++++++++++++- .../gwt/query/client/plugins/QueuePlugin.java | 4 +- .../client/plugins/events/EventsListener.java | 3 +- 3 files changed, 74 insertions(+), 6 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java index 08f6415d..ad6e1a75 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java @@ -15,6 +15,7 @@ */ package com.google.gwt.query.client; +import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.query.client.js.JsUtils; import com.google.gwt.user.client.Event; @@ -177,8 +178,7 @@ public abstract class Function { * Override this method for bound callbacks */ public void f(Object... data) { - setData(data); - f(); + fe(data); } /** @@ -267,4 +267,73 @@ public abstract class Function { } } + /** + * Methods fe(...) should be used from asynchronous contexts so as we can + * catch the exception and send it to the GWT UncaughtExceptionHandler. + * They are intentionally final to avoid override them + */ + public final void fe() { + fe((Object)null); + } + + /** + * Methods fe(...) should be used from asynchronous contexts so as we can + * catch the exception and send it to the GWT UncaughtExceptionHandler + * They are intentionally final to avoid override them + */ + public final void fe(Object data) { + fe(new Object[]{data}); + } + + /** + * Methods fe(...) should be used from asynchronous contexts so as we can + * catch the exception and send it to the GWT UncaughtExceptionHandler + * They are intentionally final to avoid override them + */ + public final void fe(Object... data) { + setData(data); + if (GWT.getUncaughtExceptionHandler() != null) { + try { + f(); + } catch (Exception e) { + GWT.getUncaughtExceptionHandler().onUncaughtException(e); + } + return; + } + f(); + } + + /** + * Methods fe(...) should be used from asynchronous contexts so as we can + * catch the exception and send it to the GWT UncaughtExceptionHandler + * They are intentionally final to avoid override them + */ + public final boolean fe(Event ev, Object data) { + if (GWT.getUncaughtExceptionHandler() != null) { + try { + return f(ev, data); + } catch (Exception e) { + GWT.getUncaughtExceptionHandler().onUncaughtException(e); + } + return true; + } + return f(ev, data); + } + + /** + * Methods fe(...) should be used from asynchronous contexts so as we can + * catch the exception and send it to the GWT UncaughtExceptionHandler + * They are intentionally final to avoid override them + */ + public final void fe(com.google.gwt.dom.client.Element elem) { + if (GWT.getUncaughtExceptionHandler() != null) { + try { + f(elem.cast()); + } catch (Exception e) { + GWT.getUncaughtExceptionHandler().onUncaughtException(e); + } + return; + } + f(elem.cast()); + } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java index 3a461a27..dc97b4b3 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java @@ -262,7 +262,7 @@ public class QueuePlugin> extends GQuery { Object f = q.peek(); if (f != null) { if (f instanceof Function) { - ((Function) f).f(elem.cast()); + ((Function) f).fe(elem); } } } @@ -279,7 +279,7 @@ public class QueuePlugin> extends GQuery { q.add(func); if (q.size() == 1) { if (func instanceof Function) { - ((Function) func).f(elem.cast()); + ((Function) func).fe(elem); } } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java index 1328d77f..7699c476 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java @@ -71,7 +71,7 @@ public class EventsListener implements EventListener { public boolean fire(Event event) { if (times != 0) { times--; - return function.f(event, data); + return function.fe(event, data); } return true; } @@ -92,7 +92,6 @@ public class EventsListener implements EventListener { */ private static class LiveBindFunction extends BindFunction { - JsNamedArray> bindFunctionBySelector; LiveBindFunction(int type, String namespace) { -- 2.39.5