My favorites | Sign in
Project Home Issues
New issue   Search
for
  Advanced search   Search tips   Subscriptions
Issue 11318: Javascript catch block NOT catching Java Method Call Exception
6 people starred this issue and may be notified of changes. Back to list
Status:  Obsolete
Owner:  ----
Closed:  Jun 2013


Sign in to add a comment
 
Reported by nirul21...@gmail.com, Sep 17, 2010

================================================

- Steps to reproduce the problem (including sample code if appropriate).

Create a simple program with a webview and from Javascript, try to call a JAVA method in which exception occurs, catch it in Javascript. Use
the following code.

Here's the java code
--------------------------------------
package com.exceptionTest;

import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebSettings;
import android.webkit.WebView;

public class myactivity extends Activity {

	private WebView browser;
	private MyInnerClass myobj;
	
	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
    
    @Override
    public void onResume() {
    	super.onResume();
    	
    	browser = new WebView(this);

    	myobj = new MyInnerClass();
    	
    	browser.addJavascriptInterface(myobj, "calc");
    	
		WebSettings settings = browser.getSettings();

		settings.setJavaScriptEnabled(true);

		browser.clearCache(true);

		browser.loadUrl("file:///android_asset/index.html");
    }
    
    public class MyInnerClass    {
    	
    	public void throwexception() throws Exception
    	{
    		throw new Exception();
    	}
    }
    
}

---------------------------------------
Here's the HTML/Javascript code
---------------------------------------
<html>
	<head>
		<title></title>
	</head>
	<body>
		<script type="text/javascript">			
			try
			{
				console.log('JAVASCRIPT TRYS!');
				
				calc.throwexception();
			}
			catch(ee)
			{
				console.log('JAVASCRIPT CATCH');
			}
		</script>
	</body>
</html>

================================================

- What happened.

In LogCat, The Java Exception occurs, the WebViewCoreThread thread crashes, VM gets aborted.

---------------------------------
09-17 20:20:52.446: INFO/ActivityManager(55): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.exceptionTest/.myactivity }
09-17 20:20:52.605: INFO/ActivityManager(55): Start proc com.exceptionTest for activity com.exceptionTest/.myactivity: pid=326 uid=10026 gids={}
09-17 20:20:52.916: DEBUG/dalvikvm(29): GC freed 263 objects / 10048 bytes in 294ms
09-17 20:20:53.095: INFO/jdwp(326): received file descriptor 20 from ADB
09-17 20:20:53.176: DEBUG/dalvikvm(29): GC freed 35 objects / 1536 bytes in 227ms
09-17 20:20:53.225: DEBUG/ddm-heap(326): Got feature list request
09-17 20:20:53.396: DEBUG/dalvikvm(29): GC freed 2 objects / 48 bytes in 189ms
09-17 20:20:54.856: INFO/ActivityManager(55): Displayed activity com.exceptionTest/.myactivity: 2357 ms (total 2357 ms)
09-17 20:20:55.346: DEBUG/WebCore(326): Console: JAVASCRIPT TRYS! line: 0 source: 
09-17 20:20:55.375: WARN/dalvikvm(326): JNI WARNING: JNI method called with exception raised
09-17 20:20:55.375: WARN/dalvikvm(326):              in Landroid/webkit/LoadListener;.nativeFinished ()V (SetIntField)
09-17 20:20:55.375: WARN/dalvikvm(326): Pending exception is:
09-17 20:20:55.375: INFO/dalvikvm(326): Ljava/lang/Exception;:
09-17 20:20:55.375: INFO/dalvikvm(326):     at com.exceptionTest.myactivity$MyInnerClass.throwexception(myactivity.java:42)
09-17 20:20:55.375: INFO/dalvikvm(326):     at android.webkit.LoadListener.nativeFinished(Native Method)
09-17 20:20:55.375: INFO/dalvikvm(326):     at android.webkit.LoadListener.nativeFinished(Native Method)
09-17 20:20:55.385: INFO/dalvikvm(326):     at android.webkit.LoadListener.tearDown(LoadListener.java:1076)
09-17 20:20:55.385: INFO/dalvikvm(326):     at android.webkit.LoadListener.handleEndData(LoadListener.java:642)
09-17 20:20:55.385: INFO/dalvikvm(326):     at android.webkit.LoadListener.handleMessage(LoadListener.java:203)
09-17 20:20:55.385: INFO/dalvikvm(326):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 20:20:55.385: INFO/dalvikvm(326):     at android.os.Looper.loop(Looper.java:123)
09-17 20:20:55.385: INFO/dalvikvm(326):     at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:471)
09-17 20:20:55.385: INFO/dalvikvm(326):     at java.lang.Thread.run(Thread.java:1060)
09-17 20:20:55.397: INFO/dalvikvm(326): "WebViewCoreThread" prio=5 tid=17 NATIVE
09-17 20:20:55.397: INFO/dalvikvm(326):   | group="main" sCount=0 dsCount=0 s=N obj=0x437620e0 self=0x1ae838
09-17 20:20:55.397: INFO/dalvikvm(326):   | sysTid=333 nice=0 sched=0/0 handle=1761696
09-17 20:20:55.397: INFO/dalvikvm(326):   at android.webkit.LoadListener.nativeFinished(Native Method)
09-17 20:20:55.397: INFO/dalvikvm(326):   at android.webkit.LoadListener.tearDown(LoadListener.java:1076)
09-17 20:20:55.397: INFO/dalvikvm(326):   at android.webkit.LoadListener.handleEndData(LoadListener.java:642)
09-17 20:20:55.397: INFO/dalvikvm(326):   at android.webkit.LoadListener.handleMessage(LoadListener.java:203)
09-17 20:20:55.397: INFO/dalvikvm(326):   at android.os.Handler.dispatchMessage(Handler.java:99)
09-17 20:20:55.397: INFO/dalvikvm(326):   at android.os.Looper.loop(Looper.java:123)
09-17 20:20:55.407: INFO/dalvikvm(326):   at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:471)
09-17 20:20:55.407: INFO/dalvikvm(326):   at java.lang.Thread.run(Thread.java:1060)
09-17 20:20:55.407: ERROR/dalvikvm(326): VM aborting
09-17 20:20:55.526: INFO/DEBUG(27): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
09-17 20:20:55.526: INFO/DEBUG(27): Build fingerprint: 'generic/sdk/generic/:1.6/Donut/20842:eng/test-keys'
09-17 20:20:55.526: INFO/DEBUG(27): pid: 326, tid: 333  >>> com.exceptionTest <<<
09-17 20:20:55.526: INFO/DEBUG(27): signal 11 (SIGSEGV), fault addr deadd00d
09-17 20:20:55.526: INFO/DEBUG(27):  r0 0000032c  r1 80000000  r2 0000000c  r3 00000026
09-17 20:20:55.526: INFO/DEBUG(27):  r4 deadd00d  r5 43787c18  r6 ad083e1c  r7 fffe6e24
09-17 20:20:55.526: INFO/DEBUG(27):  r8 44bbbda0  r9 42546ef8  10 42546ee4  fp 00000001
09-17 20:20:55.526: INFO/DEBUG(27):  ip ad083ef8  sp 44bbbc20  lr afe13f0d  pc ad03b7fa  cpsr 20000030
09-17 20:20:55.676: INFO/DEBUG(27):          #00  pc 0003b7fa  /system/lib/libdvm.so
09-17 20:20:55.686: INFO/DEBUG(27):          #01  pc 0002df7a  /system/lib/libdvm.so
09-17 20:20:55.686: INFO/DEBUG(27):          #02  pc 0002e328  /system/lib/libdvm.so
09-17 20:20:55.695: INFO/DEBUG(27):          #03  pc 0003531a  /system/lib/libdvm.so
09-17 20:20:55.695: INFO/DEBUG(27):          #04  pc 0025af86  /system/lib/libwebcore.so
09-17 20:20:55.705: INFO/DEBUG(27):          #05  pc 001c88a2  /system/lib/libwebcore.so
09-17 20:20:55.725: INFO/DEBUG(27):          #06  pc 001e16a8  /system/lib/libwebcore.so
09-17 20:20:55.725: INFO/DEBUG(27):          #07  pc 001e16ec  /system/lib/libwebcore.so
09-17 20:20:55.725: INFO/DEBUG(27):          #08  pc 001e1706  /system/lib/libwebcore.so
09-17 20:20:55.736: INFO/DEBUG(27):          #09  pc 0018b790  /system/lib/libwebcore.so
09-17 20:20:55.736: INFO/DEBUG(27):          #10  pc 0018e4d2  /system/lib/libwebcore.so
09-17 20:20:55.746: INFO/DEBUG(27):          #11  pc 0018e384  /system/lib/libwebcore.so
09-17 20:20:55.746: INFO/DEBUG(27):          #12  pc 0018bf56  /system/lib/libwebcore.so
09-17 20:20:55.756: INFO/DEBUG(27):          #13  pc 0018dbf0  /system/lib/libwebcore.so
09-17 20:20:55.756: INFO/DEBUG(27):          #14  pc 0025ad5e  /system/lib/libwebcore.so
09-17 20:20:55.766: INFO/DEBUG(27):          #15  pc 0000e434  /system/lib/libdvm.so
09-17 20:20:55.766: INFO/DEBUG(27):          #16  pc 00040b0e  /system/lib/libdvm.so
09-17 20:20:55.766: INFO/DEBUG(27):          #17  pc 00013198  /system/lib/libdvm.so
09-17 20:20:55.775: INFO/DEBUG(27):          #18  pc 00017be4  /system/lib/libdvm.so
09-17 20:20:55.775: INFO/DEBUG(27):          #19  pc 0001762c  /system/lib/libdvm.so
09-17 20:20:55.785: INFO/DEBUG(27):          #20  pc 0005282c  /system/lib/libdvm.so
09-17 20:20:55.785: INFO/DEBUG(27):          #21  pc 0005284a  /system/lib/libdvm.so
09-17 20:20:55.785: INFO/DEBUG(27):          #22  pc 00047800  /system/lib/libdvm.so
09-17 20:20:55.795: INFO/DEBUG(27):          #23  pc 0000f940  /system/lib/libc.so
09-17 20:20:55.795: INFO/DEBUG(27):          #24  pc 0000f4b4  /system/lib/libc.so
09-17 20:20:55.805: INFO/DEBUG(27): stack:
09-17 20:20:55.805: INFO/DEBUG(27):     44bbbbe0  000b1210  [heap]
09-17 20:20:55.805: INFO/DEBUG(27):     44bbbbe4  afe12f59  /system/lib/libc.so
09-17 20:20:55.805: INFO/DEBUG(27):     44bbbbe8  afe39f90  /system/lib/libc.so
09-17 20:20:55.805: INFO/DEBUG(27):     44bbbbec  afe39fe4  /system/lib/libc.so
09-17 20:20:55.817: INFO/DEBUG(27):     44bbbbf0  00000000  
09-17 20:20:55.817: INFO/DEBUG(27):     44bbbbf4  afe13f0d  /system/lib/libc.so
09-17 20:20:55.817: INFO/DEBUG(27):     44bbbbf8  001ae838  [heap]
09-17 20:20:55.817: INFO/DEBUG(27):     44bbbbfc  afe12f29  /system/lib/libc.so
09-17 20:20:55.817: INFO/DEBUG(27):     44bbbc00  fffe6e24  
09-17 20:20:55.826: INFO/DEBUG(27):     44bbbc04  ad083e1c  /system/lib/libdvm.so
09-17 20:20:55.826: INFO/DEBUG(27):     44bbbc08  43787c18  /dev/ashmem/mspace/dalvik-heap/2 (deleted)
09-17 20:20:55.826: INFO/DEBUG(27):     44bbbc0c  ad083e1c  /system/lib/libdvm.so
09-17 20:20:55.826: INFO/DEBUG(27):     44bbbc10  fffe6e24  
09-17 20:20:55.826: INFO/DEBUG(27):     44bbbc14  afe12f8d  /system/lib/libc.so
09-17 20:20:55.826: INFO/DEBUG(27):     44bbbc18  df002777  
09-17 20:20:55.836: INFO/DEBUG(27):     44bbbc1c  e3a070ad  
09-17 20:20:55.836: INFO/DEBUG(27): #00 44bbbc20  00000001  
09-17 20:20:55.846: INFO/DEBUG(27):     44bbbc24  ad02df7f  /system/lib/libdvm.so
09-17 20:20:55.846: INFO/DEBUG(27): #01 44bbbc28  ad083e1c  /system/lib/libdvm.so
09-17 20:20:55.846: INFO/DEBUG(27):     44bbbc2c  ad02e32d  /system/lib/libdvm.so
09-17 20:20:57.546: DEBUG/Zygote(29): Process 326 terminated by signal (11)
09-17 20:20:57.556: INFO/ActivityManager(55): Process com.exceptionTest (pid 326) has died.
09-17 20:20:57.565: INFO/WindowManager(55): WIN DEATH: Window{4398c220 com.exceptionTest/com.exceptionTest.myactivity paused=false}
09-17 20:20:57.696: WARN/UsageStats(55): Unexpected resume of com.android.launcher while already resumed in com.exceptionTest
09-17 20:20:57.845: WARN/InputManagerService(55): Got RemoteException sending setActive(false) notification to pid 326 uid 10026

--------------------------------------------

================================================

- What you think the correct behavior should be.

Since the Javascript try block covers the Java method called, should catch the exception in the Javascript catch block.

================================================

- Please also run "adb bugreport" and archive the output.

File Attached:

adb bugreport.txt
513 KB   View   Download
Sep 20, 2010
Project Member #1 e...@google.com
can you reproduce this in 2.2?
Status: NeedsInfo
Owner: e...@google.com
Sep 21, 2010
#2 nirul21...@gmail.com
Yes, can reproduce this in 2.2. It shows,

Android Dialog Box,
"Sorry, The application exceptionTest (process com.exceptionTest) has stopped unexpectedly. Please try again."

{Force close} Button
--------------------------------
Device Tested On Details =
Model number : Nexus One
Android version : 2.2
Baseband version : 32.36.00.28U_4.06.00.12_7
Kernel version : 2.6.32.9-27227-g3c98b0d android-build@apa26 #1
Build number : FRF91
--------------------------------
Sep 30, 2010
#3 audumbar...@gmail.com
Is there a way to handle this problem through coding?
Sep 30, 2010
Project Member #4 e...@google.com
(No comment was entered for this change.)
Owner: c...@android.com
Jun 8, 2013
#5 jbq@android.com
(No comment was entered for this change.)
Status: Obsolete
Owner: ---
Sign in to add a comment

Powered by Google Project Hosting