javierdotnet / gwt-ext

Automatically exported from code.google.com/p/gwt-ext
0 stars 3 forks source link

GWT-EXT swallows exceptions #424

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
See more details in this topic

http://www.gwt-ext.com/forum/viewtopic.php?f=7&t=2955

Original issue reported on code.google.com by mgrushin...@gmail.com on 30 Sep 2008 at 4:12

GoogleCodeExporter commented 9 years ago
FYI: copy from http://www.gwt-ext.com/forum/viewtopic.php?f=7&t=2955

danmei writes:
It seems for me, that gwt-ext swallows runtime exceptions which are thrown in a 
listener method (see code below). If you run this line of code in hosted mode 
the 
resulting exception is never shown in the hosted mode browser window.

Code:
Button b = new Button("testbutton");
b.addListener(new ButtonListenerAdapter() {
  @Override
  public void onClick(Button button, EventObject e) {
    throw new IllegalArgumentException("problem");
  }
});

Same code with the "original" gwt classes, produces a correct stack trace in 
the 
hosted mode browser.

Original comment by nietz...@gmail.com on 30 Sep 2008 at 12:09

GoogleCodeExporter commented 9 years ago
hmm, I vaguely recall noticing a difference wrt exception propagation in GWT 
1.5.
What version of GWT are you using? Have you tried running the test under GWT 1.4

Original comment by sanjiv.j...@gmail.com on 30 Sep 2008 at 1:16

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
The problem occurs with gwt 1.5.2 and gwt-ext 2.0.5/2.0.4.

Under gwt 1.4.62 and gwt-ext 2.0.5/2.0.4 the exception is caught an reported in 
the 
hosted browser (Exception thrown into Javascript).

Original comment by meier_da...@gtempaccount.com on 9 Oct 2008 at 11:22

GoogleCodeExporter commented 9 years ago
Thanks for the update. I'll create an issue with GWT along with a test case.

Original comment by sanjiv.j...@gmail.com on 9 Oct 2008 at 1:12

GoogleCodeExporter commented 9 years ago
I couldn't find a case in GWT issues, so I opened a new one

http://code.google.com/p/google-web-toolkit/issues/detail?id=3005

Original comment by mgrushin...@gmail.com on 20 Oct 2008 at 4:52

GoogleCodeExporter commented 9 years ago
This is a GWT-EXT problem.  It's the responsibility of the framework itself to 
correctly trap and hook up uncaught exceptions when a native event occurs.  The 
code 
works fine with a GWT Button.

For reference, this is what a framework must do on native events:

http://code.google.com/p/google-web-
toolkit/source/browse/tags/1.5.3/user/src/com/google/gwt/user/client/DOM.java#12
52

Original comment by sco...@google.com on 28 Oct 2008 at 4:49

GoogleCodeExporter commented 9 years ago
Thanks to Fred, I was able to take the relevant portions of the native error 
loggign
code from gwt-log. This will be incorporated in the next release of gwt-ext but 
for
now users can call LogUtil.setJSNIErrorHandler() in their onModuleLoad()

//credit Fred Sauer. The original code comes from gwt-log 
public class LogUtil {

    public static native void setJSNIErrorHandler()
        /*-{
          if ($wnd != window) {
            window.onerror =
@LogUtil::handleOnError(Ljava/lang/String;Ljava/lang/String;I);
          }

          var oldOnError = $wnd.onerror;
          $wnd.onerror = function(msg, url, line) {
            var result, oldResult;
            try {
              result =
@LogUtil::handleOnError(Ljava/lang/String;Ljava/lang/String;I)(msg, url, line);
            } finally {
              oldResult = oldOnError && oldOnError(msg, url, line);
            }
            if (result != null) return result;
            if (oldResult != null) return oldResult;
          };
        }-*/;

    private static native boolean handleOnError(String msg, String url, int line)
        /*-{
          @LogUtil::fatal(Ljava/lang/String;)("Uncaught JavaScript exception [" + msg
+ "] in " + url + ", line " + line);
          return true;
        }-*/;

    private static void fatal(String message) {
        System.err.println(message);
    }
}

Original comment by sanjiv.j...@gmail.com on 28 Oct 2008 at 7:01

GoogleCodeExporter commented 9 years ago

Original comment by sanjiv.j...@gmail.com on 28 Oct 2008 at 7:01

GoogleCodeExporter commented 9 years ago
This solution does not work for me, has there been work any fixing this IMO 
devastating issue?

Original comment by dkim...@gmail.com on 18 Feb 2009 at 9:33

GoogleCodeExporter commented 9 years ago
FYI:
if you can not compile it if you LogUtil in some package then change native
JavaScript reference @LogUtil:: to your
@com.company.product.client.gui.components.LogUtil::

later you have to look in the output of your IDE for this error.

Original comment by nietz...@gmail.com on 3 Apr 2009 at 9:48

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Hello,

I tried the solution Sanjiv posted but it does not work for me. I minimized the 
class LogUtil to this one method to find the issue:

public static native void setJSNIErrorHandler()
    /*-{
    $wnd.onerror = function(){
        alert('An error has occurred!')
    }
}-*/;

When I click on a button which throws a NullPointerException, i get only a 
log-entry 
on the javascript console of my browser. It looks like the error-event is not 
fired.

Has anyone applied this fix with success?

Original comment by seiersbr...@gmail.com on 20 Apr 2009 at 9:29

GoogleCodeExporter commented 9 years ago
I found the cause of my issue: That the event is not fired can result from 
having 
script debugging turned on, which is common for us programmers. The default is 
off, 
but it is turned on if you install any script debugger.

From the article: "A common problem that bites many developers occurs when 
their 
onerror handler is not called because they have script debugging enabled for 
Internet Explorer."

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnscrpt/html/
WebErrors2.asp

I deactivated script debugging and everything works fine.

Original comment by seiersbr...@gmail.com on 2 Jun 2009 at 1:04

GoogleCodeExporter commented 9 years ago
Interesting, thanks for the tip!

Original comment by sanjiv.j...@gmail.com on 2 Jun 2009 at 1:11

GoogleCodeExporter commented 9 years ago
I did what you suggested but I'm still not able to get my "onerror" function to 
get
called. My code:

  public void onModuleLoad()
  {
    onError();
    getError();
  }

  public static native void onError()
  /*-{
    $wnd.onerror=function()
    {
      alert("error");
    }
  }-*/;

  public native void getError()
  /*-{
    var a = null;
    a.b;
  }-*/;

Am I missing something? Shouldn't I get the alert for the error?

Note: I tried in many different browsers as well as in hosted mode

Original comment by tumo...@gmail.com on 9 Sep 2009 at 10:00