Catching a JSNI exception in "Java"

14 views
Skip to first unread message

Mat Gessel

unread,
Jun 19, 2006, 3:33:22 PM6/19/06
to GWT Group
I'm running into two problems.

1) in web mode the JavaScriptException is thrown as stated in the
docs, but in hosted mode the JSE is wrapped in a RuntimeException.

2) for most throws the nested message is "JavaScript null exception:
null". A workaround is to throw an Error object in the JS. I have not
tested this extensively, but it seems to work in IE6 and FF.
> throw new Error("JS Error Object");

If GWT is meant not to support JS syntax like "throw 1;" it should be
stated in the docs under "Exceptions and JSNI". A compile error would
be nice too, as the stack trace below is all but useless in helping a
GWT newcomer identify the source of the problem.

I have attached a test case. All test pass in web mode and all tests
fail in hosted mode.

-= Mat

java.lang.RuntimeException: JavaScript method
'@asquare.gwt.test.ThrowExceptionInJS::throwObject()' threw an
exception
at com.google.gwt.dev.shell.ie.ModuleSpaceIE6.invokeNative(ModuleSpaceIE6.java:394)
at com.google.gwt.dev.shell.ie.ModuleSpaceIE6.invokeNativeVoid(ModuleSpaceIE6.java:283)
at com.google.gwt.dev.shell.JavaScriptHost.invokeNativeVoid(JavaScriptHost.java:127)
at asquare.gwt.test.ThrowExceptionInJS.throwObject(ThrowExceptionInJS.java:65)
at asquare.gwt.test.ThrowExceptionInJS.testThrowObject(ThrowExceptionInJS.java:144)
at asquare.gwt.test.__ThrowExceptionInJS_unitTestImpl.executeTestMethod(transient
source for asquare.gwt.test.__ThrowExceptionInJS_unitTestImpl:30)
at asquare.gwt.test.__ThrowExceptionInJS_unitTestImpl$1.execute(transient
source for asquare.gwt.test.__ThrowExceptionInJS_unitTestImpl:12)
at com.google.gwt.user.client.DeferredCommand.flushDeferredCommands(DeferredCommand.java:75)
at com.google.gwt.user.client.DeferredCommand.access$2(DeferredCommand.java:56)
at com.google.gwt.user.client.DeferredCommand$1.run(DeferredCommand.java:89)
at com.google.gwt.user.client.Timer.fireImpl(Timer.java:161)
at com.google.gwt.user.client.Timer.fireAndCatch(Timer.java:147)
at com.google.gwt.user.client.Timer.fire(Timer.java:140)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.google.gwt.dev.shell.InstanceJavaDispatch.callMethod(InstanceJavaDispatch.java:40)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:127)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:199)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:108)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:1656)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:2711)
at com.google.gwt.dev.GWTShell.pumpEventLoop(GWTShell.java:491)
at com.google.gwt.dev.GWTUnitTestShell.waitForTestToComplete(GWTUnitTestShell.java:425)
at com.google.gwt.dev.GWTUnitTestShell.runTest(GWTUnitTestShell.java:401)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.google.gwt.junit.client.GWTTestCase.runTest(GWTTestCase.java:127)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at com.google.gwt.junit.client.GWTTestCase.run(GWTTestCase.java:91)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: com.google.gwt.core.client.JavaScriptException: JavaScript
null exception: null
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:274)
at com.google.gwt.dev.shell.ModuleSpace.createJavaScriptException(ModuleSpace.java:267)
at com.google.gwt.dev.shell.ie.ModuleSpaceIE6.exceptionCaught(ModuleSpaceIE6.java:105)
at com.google.gwt.dev.shell.JavaScriptHost.exceptionCaught(JavaScriptHost.java:31)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:324)
at com.google.gwt.dev.shell.StaticJavaDispatch.callMethod(StaticJavaDispatch.java:45)
at com.google.gwt.dev.shell.ie.IDispatchProxy.invoke(IDispatchProxy.java:127)
at com.google.gwt.dev.shell.ie.IDispatchImpl.Invoke(IDispatchImpl.java:199)
at com.google.gwt.dev.shell.ie.IDispatchImpl.method6(IDispatchImpl.java:108)
at org.eclipse.swt.internal.ole.win32.COMObject.callback6(COMObject.java:117)
at org.eclipse.swt.internal.ole.win32.COM.VtblCall(Native Method)
at org.eclipse.swt.internal.ole.win32.IDispatch.Invoke(IDispatch.java:64)
at org.eclipse.swt.ole.win32.OleAutomation.invoke(OleAutomation.java:487)
at org.eclipse.swt.ole.win32.OleAutomation.invoke(OleAutomation.java:413)
at com.google.gwt.dev.shell.ie.ModuleSpaceIE6.invokeNative(ModuleSpaceIE6.java:365)
... 43 more

ThrowExceptionInJS.java

Scott Blum

unread,
Jun 20, 2006, 9:10:26 AM6/20/06
to Google Web Toolkit
Hi Mat,

Good catch. You're right, our JS exception support is designed to work
with the real JS error types. Specifically, I believe e.name and
e.message are used to populate the wrapper object. All of the
implicitly-generated JS exceptions support this, and that was the
target use case. I don't think we had throwing primitives or non-Error
type Objects in mind when we designed it, so that should be mentioned
in the doc.

Scott

Reply all
Reply to author
Forward
0 new messages