Have you tried setting an uncaught exception handler?
You can use gwt-log (http://code.google.com/p/gwt-log/) to do this:
public void onModuleLoad() {
Log.setUncaughtExceptionHandler();
DeferredCommand.addCommand(new Command() {
public void execute() {
onModuleLoad2();
}
});
}
private void onModuleLoad2() {
// Your client code goes here
}
Or, you can use this rudimentary approach:
public void onModuleLoad() {
// set uncaught exception handler
GWT.setUncaughtExceptionHandler(new GWT.UncaughtExceptionHandler() {
public void onUncaughtException(Throwable throwable) {
String text = "Uncaught exception: ";
while (throwable != null) {
StackTraceElement[] stackTraceElements = throwable.getStackTrace();
text += throwable.toString() + "\n";
for (int i = 0; i < stackTraceElements.length; i++) {
text += " at " + stackTraceElements[i] + "\n";
}
throwable = throwable.getCause();
if (throwable != null) {
text += "Caused by: ";
}
}
DialogBox dialogBox = new DialogBox(true, false);
DOM.setStyleAttribute(dialogBox.getElement(),
"backgroundColor", "#ABCDEF");
System.err.print(text);
text = text.replaceAll(" ", " ");
dialogBox.setHTML("<pre>" + text + "</pre>");
dialogBox.center();
}
});
// use a deferred command so that the handler catches
onModuleLoad2() exceptions
DeferredCommand.addCommand(new Command() {
public void execute() {
onModuleLoad2();
}
});
}
private void onModuleLoad2() {
// .....
}
Fred
On Mon, Oct 25, 2010 at 2:14 AM, Carl <[email protected]> wrote:
> Hi, I sporadically receive the exception shown below or simular. This
> is in development mode. I'm not sure about production mode. Is there a
> way to catch all exceptions in GWT?
>
> I don't see any of my lines in the exception and wonder what I can do
> to avoid this in the future.
>
> I use GWT 2.0.4, OS X 10.6.4 and Safari 5.0.2.
>
> java.lang.ClassCastException: null
> at java.lang.Class.cast(Class.java:2990)
> at com.google.gwt.dev.shell.JsValueGlue.get(JsValueGlue.java:166)
> at
> com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:57)
> at
>
> com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:
> 157)
> at
>
> com.google.gwt.dev.shell.BrowserChannel.reactToMessagesWhileWaitingForReturn(BrowserChannel.java:
> 1714)
> at
>
> com.google.gwt.dev.shell.BrowserChannelServer.invokeJavascript(BrowserChannelServer.java:
> 165)
> at
> com.google.gwt.dev.shell.ModuleSpaceOOPHM.doInvoke(ModuleSpaceOOPHM.java:
> 120)
> at
> com.google.gwt.dev.shell.ModuleSpace.invokeNative(ModuleSpace.java:
> 507)
> at
> com.google.gwt.dev.shell.ModuleSpace.invokeNativeObject(ModuleSpace.java:
> 264)
> at
>
> com.google.gwt.dev.shell.JavaScriptHost.invokeNativeObject(JavaScriptHost.java:
> 91)
> at com.google.gwt.core.client.impl.Impl.apply(Impl.java)
> at com.google.gwt.core.client.impl.Impl.entry0(Impl.java:188)
> at sun.reflect.GeneratedMethodAccessor95.invoke(Unknown Source)
> at
>
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:
> 25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> com.google.gwt.dev.shell.MethodAdaptor.invoke(MethodAdaptor.java:103)
> at
> com.google.gwt.dev.shell.MethodDispatch.invoke(MethodDispatch.java:71)
> at
>
> com.google.gwt.dev.shell.OophmSessionHandler.invoke(OophmSessionHandler.java:
> 157)
> at
>
> com.google.gwt.dev.shell.BrowserChannel.reactToMessages(BrowserChannel.java:
> 1669)
> at
>
> com.google.gwt.dev.shell.BrowserChannelServer.processConnection(BrowserChannelServer.java:
> 401)
> at
>
> com.google.gwt.dev.shell.BrowserChannelServer.run(BrowserChannelServer.java:
> 222)
> at java.lang.Thread.run(Thread.java:680)
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-web-toolkit%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-web-toolkit?hl=en.
>
>
--
Fred Sauer
Developer Advocate
Google Inc.
1600 Amphitheatre Parkway
Mountain View, CA 94043
[email protected]
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-web-toolkit?hl=en.