Friday, September 11, 2015

Print uncaught exception in SDM

I tried a few methods to print the stack trace properly in SDM when a JavaScriptException is caught by UncaughtExceptionHandler.

Finally I come up with the code below

GWT.setUncaughtExceptionHandler(e -> {
   
if (e instanceof UmbrellaException) {
        e
= e.getCause();
   
}
   
if (e instanceof JavaScriptException) {
       
JavaScriptException jsError = (JavaScriptException) e;
       
if (jsError.isThrownSet() && jsError.getThrown() instanceof JavaScriptObject) {
           
JsObject jsThrown = (JsObject) jsError.getThrown(); // JsObject is a wrapper of JavaScriptObject
            GWT.log(jsThrown.getString("stack"));
           
return;
       
}
   
}
    GWT
.log(e.getMessage(), e);
});

The basic idea is to print the stack property of a JS Error object. Is there a better way of doing this?

--
You received this message because you are subscribed to the Google Groups "GWT Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-web-toolkit+unsubscribe@googlegroups.com.
To post to this group, send email to google-web-toolkit@googlegroups.com.
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment